{"record":{"id":"6853d019b1c7478d","repo":"garrytan/gstack","slug":"authentication-failed","errorCode":null,"errorMessage":"Authentication failed","messagePattern":"Authentication failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browse/src/cli.ts","lineNumber":555,"sourceCode":"  try {\n    const resp = await fetch(`http://127.0.0.1:${state.port}/command`, {\n      method: 'POST',\n      headers: {\n        'Content-Type': 'application/json',\n        'Authorization': `Bearer ${state.token}`,\n      },\n      body,\n      signal: AbortSignal.timeout(30000),\n    });\n\n    if (resp.status === 401) {\n      // Token mismatch — server may have restarted\n      console.error('[browse] Auth failed — server may have restarted. Retrying...');\n      const newState = readState();\n      if (newState && newState.token !== state.token) {\n        return sendCommand(newState, command, args);\n      }\n      throw new Error('Authentication failed');\n    }\n\n    const text = await resp.text();\n\n    if (resp.ok) {\n      process.stdout.write(text);\n      if (!text.endsWith('\\n')) process.stdout.write('\\n');\n    } else {\n      // Try to parse as JSON error\n      try {\n        const err = JSON.parse(text);\n        console.error(err.error || text);\n        if (err.hint) console.error(err.hint);\n      } catch {\n        console.error(text);\n      }\n      process.exit(1);\n    }","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/browse/src/cli.ts#L537-L573","documentation":"Error \"Authentication failed\" thrown in garrytan/gstack.","triggerScenarios":"Thrown at browse/src/cli.ts:555 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}