{"record":{"id":"bdbaf2a3c8bec433","repo":"facebook/docusaurus","slug":"an-error-occurred-when-trying-to-get-the-file-ag","errorCode":null,"errorMessage":"An error occurred when trying to get the file ${age === 'oldest' ? 'creation' : 'last update'} date from Git","messagePattern":"An error occurred when trying to get the file (.+?) date from Git","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/docusaurus-utils/src/vcs/gitUtils.ts","lineNumber":240,"sourceCode":"      includeAuthor: true,\n    });\n    return {timestamp: result.timestamp, author: result.author};\n  } catch (err) {\n    // TODO legacy perf issue: do not use exceptions for control flow!\n    if (err instanceof GitNotFoundError) {\n      if (!showedGitRequirementError) {\n        logger.warn('Sorry, the last update options require Git.');\n        showedGitRequirementError = true;\n      }\n    } else if (err instanceof FileNotTrackedError) {\n      if (!showedFileNotTrackedError) {\n        logger.warn(\n          'Cannot infer the update date for some files, as they are not tracked by git.',\n        );\n        showedFileNotTrackedError = true;\n      }\n    } else {\n      throw new Error(\n        `An error occurred when trying to get the file ${\n          age === 'oldest' ? 'creation' : 'last update'\n        } date from Git`,\n        {cause: err},\n      );\n    }\n    return null;\n  }\n}\n\nexport async function getGitLastUpdate(\n  filePath: string,\n): Promise<GitCommitInfo | null> {\n  return getGitCommitInfo(filePath, 'newest');\n}\n\nexport async function getGitCreation(\n  filePath: string,","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-utils/src/vcs/gitUtils.ts#L222-L258","documentation":"Thrown by getGitCommitInfo() as a wrapper-level catch-all after getFileCommitDate rejects with an error that is neither GitNotFoundError nor FileNotTrackedError. Those two known cases are downgraded to a single logger.warn; any other failure (file-missing, non-zero exit, unexpected output, or a generic git invocation error) is re-thrown wrapped with context indicating whether the build was seeking 'creation' (age=oldest) or 'last update' (age=newest) dates.","triggerScenarios":"Any of errors 94, 95, or 97 bubbling up through getGitCommitInfo — i.e. the file does not exist, git exited non-zero, or the log output was unparseable. Since getGitCommitInfo catches only the two custom error classes, every other throw from getFileCommitDate is wrapped here.","commonSituations":"Building with showLastUpdateTime while a content file is missing, the repo is corrupted, or git produced unexpected output (see the underlying errors 94/95/97). The wrapper error hides the original behind a generic message, so the cause property must be inspected to find the real failure.","solutions":["Inspect the cause property of the thrown error — it is the underlying Error from getFileCommitDate (errors 94, 95, or 97).","Apply the fix appropriate to the cause: restore the missing file (94), repair the repo / remove stale locks (95), or address the git output issue (97).","If you call getGitLastUpdate / getGitCreation directly and want to tolerate transient failures, wrap them in try/catch and fall back to null.","Re-run the build after resolving the underlying cause."],"exampleFix":"// before — caller propagates the wrapper unconditionally\nconst info = await getGitLastUpdate(filePath);\n\n// after — caller degrades gracefully when git info is unavailable\nlet info = null;\ntry {\n  info = await getGitLastUpdate(filePath);\n} catch (err) {\n  console.warn(`Skipping git info for ${filePath}: ${err.cause ?? err}`);\n}","handlingStrategy":"try-catch","validationCode":"import fs from 'fs-extra';\n\nasync function safeToQueryGit(file: string): Promise<boolean> {\n  return await fs.pathExists(file);\n}\n\nif (!(await safeToQueryGit(file))) return null;","typeGuard":null,"tryCatchPattern":"try {\n  await getGitLastUpdate(filePath);\n} catch (err) {\n  // err.cause is the underlying getFileCommitDate error (94/95/97)\n  console.warn(`Git info unavailable for ${filePath}: ${err.cause ?? err}`);\n  return null;\n}","preventionTips":["Inspect err.cause — the wrapper hides the real failure behind a generic message.","Resolve the underlying cause (missing file, corrupted repo, unexpected git output) using errors 94/95/97 guidance.","If you call getGitLastUpdate / getGitCreation directly, wrap them in try/catch and degrade to null when git info is non-critical."],"tags":["git","wrapper","vcs","build"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}