nocobase/nocobase · error · Error
Couldn't locate the saved stash for source publish: ${params
Error message
Couldn't locate the saved stash for source publish: ${params.stash.commit} What it means
resolveSourcePublishStashReference() scans `git stash list --format=%gd%x00%H` to translate the recorded stash commit SHA into a stash reference (e.g. stash@{0}) so it can be applied/popped. If no stash entry's commit hash matches the SHA captured when the stash was created, the CLI throws this error, because it cannot safely reference the stashed working-tree changes.
Source
Thrown at packages/core/cli/src/lib/source-publish.ts:209
};
}
async function resolveSourcePublishStashReference(params: {
cwd: string;
stash: SourcePublishStash;
}): Promise<string> {
const output = trimValue(await commandOutput('git', ['stash', 'list', '--format=%gd%x00%H'], {
cwd: params.cwd,
errorName: 'git stash list',
}));
for (const line of output.split('\n')) {
const [reference, commit] = line.split('\x00');
if (trimValue(commit) === params.stash.commit) {
return trimValue(reference);
}
}
throw new Error(`Couldn't locate the saved stash for source publish: ${params.stash.commit}`);
}
function buildSourcePublishRecoveryError(params: {
originalError: unknown;
cleanupError: unknown;
stash?: SourcePublishStash;
temporaryBranch: string;
projectRoot: string;
}): Error {
const originalMessage = params.originalError instanceof Error
? params.originalError.message
: String(params.originalError);
const cleanupMessage = params.cleanupError instanceof Error
? params.cleanupError.message
: String(params.cleanupError);
const recoveryHints = [
`Project root: ${params.projectRoot}`,
`Temporary branch: ${params.temporaryBranch}`,View on GitHub (pinned to fa42722fef)
Solutions
- Check `git stash list` for a stash whose SHA matches the commit printed in the error
- If present, apply it manually: `git stash apply --index stash@{N}`, then re-run the publish
- If absent, your uncommitted changes were dropped — recover via `git fsck --unrooted` / `git fsck --dangling | grep commit` and inspect dangling commits for the stash
- Avoid touching stashes in other terminals while `nb source publish --snapshot` runs
Example fix
// before: stash vanished mid-publish error: Couldn't locate the saved stash for source publish: 3f9c1ab... // after: recover dangling stash commit $ git fsck --dangling | grep commit $ git show <dangling-sha> # verify it is your stash $ git stash apply <dangling-sha>
Defensive patterns
Strategy: validation
Validate before calling
const stashList = await exec('git stash list --format=%gd%x00%H');
const found = stashList.split('\n').some((l) => l.split('\u0000')[1]?.trim() === stashCommit);
if (!found) throw new Error(`Stash ${stashCommit} missing; recover before publishing`); Type guard
function stashExists(stashList: string, commit: string): boolean {
return stashList.split('\n').some((line) => line.split('\u0000')[1]?.trim() === commit);
} Try / catch
try {
await publishSourceSnapshot({ npmRegistry });
} catch (err) {
if (String(err.message).startsWith("Couldn't locate the saved stash")) {
console.error('Recover via: git fsck --dangling | grep commit, then git stash apply <sha>');
} else throw err;
} Prevention
- Do not run git stash pop/drop/clear in other terminals while a publish is in progress
- Run publish with committed changes (stash-free) when possible to avoid stashing entirely
- Record the stash SHA output at publish start so you can recover manually
- Avoid running git gc --prune=now during a publish
When it happens
Trigger: During publishSourceSnapshot, after `git stash push -u` recorded a commit SHA, a later `git stash apply --index <ref>` or cleanup-time `git stash pop` cannot find that SHA in the stash list — typically because the stash was dropped/popped elsewhere (another terminal, `git stash drop/clear`), or the stash list format output changed/was truncated between creation and lookup.
Common situations: Developer pops or clears the stash in a parallel terminal while the publish is running; `git gc`/`git stash clear` pruned the stash; running publish on a repo where another tool manages stashes; git versions where the custom --format rendering differs across locales.
Related errors
- The current Git branch reference is invalid: ${branch}.\nThi
- `nb source publish --snapshot` requires a named Git branch.
- The source snapshot was published, but local Git cleanup fai
- Source snapshot publishing finished without a result.
- ${originalMessage} Cleanup also failed after the publish at
AI-assisted analysis of nocobase/nocobase@fa42722fef (2026-09-01).
Data as JSON: /api/errors/1ef2106c7c9fdb1c.
Report an issue: GitHub.