{"record":{"id":"474c46d495e27730","repo":"kataras/iris","slug":"not-found","errorCode":null,"errorMessage":"not found","messagePattern":"not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"context/context.go","lineNumber":1581,"sourceCode":"// URLParamEscape returns the escaped url query parameter from a request.\nfunc (ctx *Context) URLParamEscape(name string) string {\n\treturn DecodeQuery(ctx.URLParam(name))\n}\n\n// ErrNotFound is the type error which API users can make use of\n// to check if a `Context` action of a `Handler` is type of Not Found,\n// e.g. URL Query Parameters.\n// Example:\n//\n// n, err := context.URLParamInt(\"url_query_param_name\")\n//\n//\tif errors.Is(err, context.ErrNotFound) {\n//\t\t// [handle error...]\n//\t}\n//\n// Another usage would be `err == context.ErrNotFound`\n// HOWEVER prefer use the new `errors.Is` as API details may change in the future.\nvar ErrNotFound = errors.New(\"not found\")\n\n// URLParamInt returns the url query parameter as int value from a request,\n// returns -1 and an error if parse failed or not found.\nfunc (ctx *Context) URLParamInt(name string) (int, error) {\n\tif v := ctx.URLParam(name); v != \"\" {\n\t\tn, err := strconv.Atoi(v)\n\t\tif err != nil {\n\t\t\treturn -1, err\n\t\t}\n\t\treturn n, nil\n\t}\n\n\treturn -1, ErrNotFound\n}\n\n// URLParamIntDefault returns the url query parameter as int value from a request,\n// if not found or parse failed then \"def\" is returned.\nfunc (ctx *Context) URLParamIntDefault(name string, def int) int {","sourceCodeStart":1563,"sourceCodeEnd":1599,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/context.go#L1563-L1599","documentation":"ErrNotFound is the sentinel error of Context's key-value storage (ctx.Get, ctx.Set, Update, Delete, GetByID in the Context store / Params / memstore). It is returned when the requested key or ID does not exist. The docs recommend errors.Is(err, context.ErrNotFound) since exact equality may break in future versions.","triggerScenarios":"Calling ctx.Get/GetByID/Update/Delete with a key or ID that was never set, or after it was removed; reading a stored value before the handler/middleware that sets it has run.","commonSituations":"Middleware ordering mistakes (reading a session/user value before the middleware that stores it); typos in key names; expecting a value across requests when it is only per-request; deleting a key twice.","solutions":["Use errors.Is(err, context.ErrNotFound) to detect the missing-key case and handle it (create default, return 404, etc.).","Verify the key/ID spelling matches exactly what was stored via ctx.Set.","Check middleware/handler ordering so the value is set before it is read.","If the value should persist across requests, use a session or database instead of the per-request context store."],"exampleFix":"// before\nv, err := ctx.Get(\"userID\")\nuserID := v.(int) // panics if not found\n// after\nv, err := ctx.Get(\"userID\")\nif err != nil {\n    if errors.Is(err, context.ErrNotFound) {\n        ctx.StopWithStatus(iris.StatusNotFound)\n        return\n    }\n    return\n}","handlingStrategy":"try-catch","validationCode":"// nothing to validate beforehand if you don't control the key lifecycle;\n// verify the key was set earlier:\n//   ctx.Set(\"userID\", 42)\n// then reading with Get must use the exact same key string","typeGuard":"func hasValue(ctx iris.Context, key string) bool {\n    _, err := ctx.Get(key)\n    return !errors.Is(err, context.ErrNotFound)\n}","tryCatchPattern":"v, err := ctx.Get(\"userID\")\nif err != nil {\n    if errors.Is(err, context.ErrNotFound) { // prefer errors.Is per docs\n        ctx.StopWithStatus(iris.StatusNotFound)\n        return\n    }\n    return\n}","preventionTips":["Always use errors.Is(err, context.ErrNotFound) instead of == comparison, as the docs warn API details may change.","Define key names as constants to avoid typos between Set and Get.","Ensure middleware that stores values runs before handlers that read them.","Do not assume per-request store values persist across requests; use sessions/storage for durable data."],"tags":["key-value","not-found","context","sentinel-error"],"backgroundTag":"key-not-found","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}