fix(docs): split work-product open errors into actionable reasons

The previous handler folded every null target into one error code
("WORK_PRODUCT_NOT_FOUND: Work product not found or its workspace
is unresolved"). When a user couldn't open a file we had no way to
tell whether the row was archived, the provider/external_id was
empty, the workspace had no local_path, or the external_id escaped
the root.

Widen resolveWorkProductTarget's return from (target | null) to
(target | error) where error carries one of five reasons:

  not_found             row missing for id+company
  archived              status == "archived" tombstone
  no_target             provider != filesystem and no url
  workspace_unresolved  all three workspace_id / task_id / run_id
                         lookups returned no local_path
  path_escape           external_id is absolute or steps outside root

Each reason includes the concrete detail (ids checked, paths tried)
so the toast on the renderer side tells the user exactly which slot
is null without having to open the DB.

The IPC handler maps each reason to its own failure code and passes
the detail through, so WorkProductRow's toast now reads e.g.
"workspace_id=null task_id=null run_id=null — none led to a
workspace with a local_path" instead of a generic unresolved.

Typecheck and build:verify clean.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-21 14:45:59 -04:00
1 parent 9f43549606
commit 390f76fa76
2 files changed
+31 -12

No files matched your search

+10 -1
View File
@@ -69,7 +69,16 @@ export function registerCoreReadHandlers({
const companyError = ensureCompanyExists(parsed.data.companyId);
if (companyError) return companyError;
const target = db.documentsMod.resolveWorkProductTarget(parsed.data.id, parsed.data.companyId);
if (!target) return fail("WORK_PRODUCT_NOT_FOUND", "Work product not found or its workspace is unresolved.");
if (target.kind === "error") {
const codeByReason = {
not_found: "WORK_PRODUCT_NOT_FOUND",
archived: "WORK_PRODUCT_ARCHIVED",
no_target: "WORK_PRODUCT_NO_TARGET",
workspace_unresolved: "WORK_PRODUCT_WORKSPACE_UNRESOLVED",
path_escape: "WORK_PRODUCT_PATH_ESCAPE",
} as const;
return fail(codeByReason[target.reason], target.detail);
}
if (target.kind === "url") {
const error = await shell.openExternal(target.value).then(() => "").catch((err: unknown) => err instanceof Error ? err.message : String(err));
return error ? fail("OPEN_PATH_FAILED", error) : ok(true);