{"record":{"id":"1e503eb4fc78de3b","repo":"kataras/iris","slug":"build-w","errorCode":null,"errorMessage":"build: %w","messagePattern":"build: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"iris.go","lineNumber":687,"sourceCode":"// It builds the default router with its default macros\n// and the template functions that are very-closed to iris.\n//\n// If error occurred while building the Application, the returns type of error will be an *errgroup.Group\n// which let the callers to inspect the errors and cause, usage:\n//\n// import \"github.com/kataras/iris/v12/core/errgroup\"\n//\n//\terrgroup.Walk(app.Build(), func(typ any, err error) {\n//\t\tapp.Logger().Errorf(\"%s: %s\", typ, err)\n//\t})\nfunc (app *Application) Build() error {\n\tif app.builded {\n\t\treturn nil\n\t}\n\n\tif cb := app.OnBuild; cb != nil {\n\t\tif err := cb(); err != nil {\n\t\t\treturn fmt.Errorf(\"build: %w\", err)\n\t\t}\n\t}\n\n\t// start := time.Now()\n\tapp.builded = true // even if fails.\n\n\t// check if a prior app.Logger().SetLevel called and if not\n\t// then set the defined configuration's log level.\n\tif app.logger.Level == golog.InfoLevel /* the default level */ {\n\t\tapp.logger.SetLevel(app.config.LogLevel)\n\t}\n\n\tif app.defaultMode { // the app.I18n and app.View will be not available until Build.\n\t\tif !app.I18n.Loaded() {\n\t\t\tfor _, s := range []string{\"./locales/*/*\", \"./locales/*\", \"./translations\"} {\n\t\t\t\tif _, err := os.Stat(s); err != nil {\n\t\t\t\t\tcontinue\n\t\t\t\t}","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/iris.go#L669-L705","documentation":"iris.Application.Build runs the app's OnBuild hook and marks the app as built during server construction (New/NewServer/Run). If the user-supplied OnBuild callback returns an error, it is wrapped as \"build: err\". It means application-level build/registration logic provided by the user failed before the server could start.","triggerScenarios":"Assigning app.OnBuild = func() error {...} whose callback returns an error; Build is then invoked automatically by New, NewServer, or Run, and the callback's error surfaces wrapped as \"build: ...\".","commonSituations":"OnBuild hooks doing dependency checks, config validation, or route/middleware registration that fail — e.g. DB ping failure, missing config, or an already-registered dependency — during app startup in main().","solutions":["Read the wrapped inner error — it originates from your OnBuild callback, not Iris itself.","Fix the failing logic inside your OnBuild function (check connections, config, registrations).","Add context to the error returned by OnBuild to pinpoint the failing step.","Note that app.builded is set even on failure; create a fresh app instance rather than retrying Build on the same one."],"exampleFix":"// before\napp.OnBuild = func() error { return db.Ping() } // opaque \"build: ...\"\n// after\napp.OnBuild = func() error {\n    if err := db.Ping(); err != nil {\n        return fmt.Errorf(\"onbuild: db ping failed: %w\", err)\n    }\n    return nil\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"app.OnBuild = func() error {\n    if err := setup(); err != nil {\n        return fmt.Errorf(\"onbuild setup: %w\", err)\n    }\n    return nil\n}\nif err := app.Build(); err != nil {\n    var inner error\n    if errors.As(err, &inner) {\n        log.Printf(\"build hook failed: %v\", inner)\n    }\n    os.Exit(1)\n}","preventionTips":["Return descriptive errors from OnBuild — they're surfaced wrapped as \"build: ...\".","Keep OnBuild side effects idempotent; builded is set even on failure.","Do heavy dependency checks (DB, Redis) in OnBuild with clear error context.","Test startup in CI so hook failures surface before production."],"tags":["iris","go","lifecycle","startup"],"backgroundTag":"app-build-hook-failed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}