/**
 * Next.js mints a fresh id for every server action on every build, so a page
 * left open across a deploy calls ids that no longer exist and the framework
 * surfaces "Server Action ... was not found on the server". That is not a bug
 * the reader can act on, and it is not what it sounds like — the fix is simply
 * to reload.
 *
 * Single-server app deployed several times a day, so this is common enough to
 * be worth naming properly.
 */
export function friendlyActionError(err: unknown): string {
  const message = err instanceof Error ? err.message : String(err)
  if (
    message.includes('was not found on the server') ||
    message.includes('Failed to find Server Action')
  ) {
    return 'This page is from an older version of the app — refresh and try again. Nothing was lost.'
  }
  if (message.includes('NEXT_REDIRECT')) return ''
  return message
}
