@@ -67,6 +67,8 @@ func Run(homeDir app.File, meta app.Meta, config app.Config, args []string) (int
6767 }),
6868 )
6969 if nErr != nil {
70+ // This code branch is not expected to be invoked in practice. If it were to
71+ // happen, that most likely indicates a bug in the app setup.
7072 return app .GENERAL_ERROR .ToInt (), errors .New ("Internal error: " + nErr .Error ())
7173 }
7274
@@ -95,18 +97,19 @@ func Run(homeDir app.File, meta app.Meta, config app.Config, args []string) (int
9597 kongCtx .BindTo (ctx , (* app .Context )(nil ))
9698
9799 rErr := kongCtx .Run ()
98- if rErr != nil {
99- if errors .Is (rErr , app .NewParserErrors (nil )) {
100- var e app.ParserErrors
101- errors .As (rErr , & e )
102- return e .Code ().ToInt (), util .PrettifyParsingError (e , styler )
103- } else if errors .Is (rErr , app .NewError ("" , "" , nil )) {
104- var e app.Error
105- errors .As (rErr , & e )
106- return e .Code ().ToInt (), util .PrettifyAppError (e , config .IsDebug .Value ())
107- } else {
108- return app .GENERAL_ERROR .ToInt (), errors .New ("Error: " + rErr .Error ())
109- }
100+ parserErrors := app .NewParserErrors (nil )
101+ appError := app .NewError ("" , "" , nil )
102+
103+ switch {
104+ case rErr == nil :
105+ return 0 , nil
106+ case errors .As (rErr , & parserErrors ):
107+ return parserErrors .Code ().ToInt (), util .PrettifyParsingError (parserErrors , styler )
108+ case errors .As (rErr , & appError ):
109+ return appError .Code ().ToInt (), util .PrettifyAppError (appError , config .IsDebug .Value ())
110+ default :
111+ // This is just a fallback clause; this code branch is not expected to be
112+ // invoked in practice.
113+ return app .GENERAL_ERROR .ToInt (), errors .New ("Error: " + rErr .Error ())
110114 }
111- return 0 , nil
112115}
0 commit comments