{"record":{"id":"15021fbb05d64212","repo":"wavetermdev/waveterm","slug":"errnotfound","errorCode":"ErrNotFound","errorMessage":"not found","messagePattern":"not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"pkg/wstore/wstore_dbops.go","lineNumber":20,"sourceCode":"// SPDX-License-Identifier: Apache-2.0\n\npackage wstore\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"reflect\"\n\t\"regexp\"\n\t\"time\"\n\n\t\"github.com/wavetermdev/waveterm/pkg/filestore\"\n\t\"github.com/wavetermdev/waveterm/pkg/panichandler\"\n\t\"github.com/wavetermdev/waveterm/pkg/util/dbutil\"\n\t\"github.com/wavetermdev/waveterm/pkg/waveobj\"\n)\n\nvar ErrNotFound = fmt.Errorf(\"not found\")\n\nfunc waveObjTableName(w waveobj.WaveObj) string {\n\treturn \"db_\" + w.GetOType()\n}\n\nfunc tableNameFromOType(otype string) string {\n\treturn \"db_\" + otype\n}\n\nfunc tableNameGen[T waveobj.WaveObj]() string {\n\tvar zeroObj T\n\treturn tableNameFromOType(zeroObj.GetOType())\n}\n\nfunc getOTypeGen[T waveobj.WaveObj]() string {\n\tvar zeroObj T\n\treturn zeroObj.GetOType()\n}","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wstore/wstore_dbops.go#L2-L38","documentation":"ErrNotFound is the sentinel error wstore returns when a queried object does not exist in the database (via DBGet/DBGetORef and friends). Callers should compare with errors.Is(err, wstore.ErrNotFound) to distinguish 'absent' from real failures.","triggerScenarios":"Calling GetProcInfo/readStat/readUid, EnsureInitialData, InitMainServer, or DeleteWorkspace with an identifier (oid, pid, uid) that has no row in the wstore database.","commonSituations":"Looking up a process that has already exited; querying a workspace/server that was deleted or not yet initialized; wrong database file (e.g. dev vs prod WAVETERM_HOME) so the expected row is missing.","solutions":["Treat it as an expected outcome: use errors.Is(err, wstore.ErrNotFound) to branch instead of failing hard","Create the object first (DBInsert / the relevant Ensure*/Init* function) before reading it","Confirm you are pointing at the correct wstore database and the ID was obtained from the same instance","Re-fetch current IDs instead of caching ones that may have been deleted"],"exampleFix":"// before\nobj, err := wstore.DBGetORef(ctx, oref)\nif err != nil { return err }\n// after\nobj, err := wstore.DBGetORef(ctx, oref)\nif errors.Is(err, wstore.ErrNotFound) {\n\treturn createDefault(ctx, oref) // or return nil\n}\nif err != nil { return err }","handlingStrategy":"try-catch","validationCode":"obj, _ := wstore.DBGetORef(ctx, oref)\nif obj == nil { /* handle absence before calling APIs that expect it */ }","typeGuard":"func isNotFound(err error) bool { return errors.Is(err, wstore.ErrNotFound) }","tryCatchPattern":"obj, err := wstore.DBGetORef(ctx, oref)\nswitch {\ncase errors.Is(err, wstore.ErrNotFound):\n\t// create or default path\n\treturn ensureExists(ctx, oref)\ncase err != nil:\n\treturn err\n}","preventionTips":["Compare with errors.Is against wstore.ErrNotFound, never string matching","Create objects before reading them","Verify you are on the same database instance that holds the ID"],"tags":["sentinel-error","sqlite","not-found"],"backgroundTag":"record-not-found","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}