Improve raising exceptions in config
What does this Merge Request do?
This MR introduces the GDK::ConfigSettings::UnsupportedConfiguration
error class that is explicitly thrown and caught to improve the user experience, e.g.
Before
Examples using changes from !1859 (merged):
Click this to collapse/fold.
$ gdk config get runner.__network_mode_host
Traceback (most recent call last):
16: from /Users/ash/.asdf/installs/ruby/2.7.2/bin/gdk:23:in `<main>'
15: from /Users/ash/.asdf/installs/ruby/2.7.2/bin/gdk:23:in `load'
14: from /Users/ash/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/gitlab-development-kit-0.2.10/bin/gdk:130:in `<top (required)>'
13: from /Users/ash/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/gitlab-development-kit-0.2.10/bin/gdk:77:in `launcher_main'
12: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk.rb:64:in `main'
11: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/command/config.rb:15:in `run'
10: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:167:in `dig'
9: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:163:in `dig'
8: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:149:in `fetch'
7: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:149:in `public_send'
6: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:78:in `block in def_attribute'
5: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:223:in `build'
4: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `build'
3: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `new'
2: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:16:in `initialize'
1: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:22:in `read_value'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:22:in `fetch': key not found: "__network_mode_host" (KeyError)
Did you mean? "network_mode_host"
19: from /Users/ash/.asdf/installs/ruby/2.7.2/bin/gdk:23:in `<main>'
18: from /Users/ash/.asdf/installs/ruby/2.7.2/bin/gdk:23:in `load'
17: from /Users/ash/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/gitlab-development-kit-0.2.10/bin/gdk:130:in `<top (required)>'
16: from /Users/ash/.asdf/installs/ruby/2.7.2/lib/ruby/gems/2.7.0/gems/gitlab-development-kit-0.2.10/bin/gdk:77:in `launcher_main'
15: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk.rb:64:in `main'
14: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/command/config.rb:15:in `run'
13: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:167:in `dig'
12: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:163:in `dig'
11: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:149:in `fetch'
10: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:149:in `public_send'
9: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:78:in `block in def_attribute'
8: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:223:in `build'
7: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `build'
6: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `new'
5: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:16:in `initialize'
4: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:21:in `read_value'
3: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:24:in `rescue in read_value'
2: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:28:in `default_value'
1: from /Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:28:in `instance_eval'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config.rb:450:in `block (2 levels) in <class:Config>': uninitialized constant GDK::Config::UnsupportedConfiguration (NameError)
$ make gitlab-runner-config.toml
rake aborted!
NameError: uninitialized constant GDK::Config::UnsupportedConfiguration
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config.rb:450:in `block (2 levels) in <class:Config>'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:28:in `instance_eval'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:28:in `default_value'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:24:in `rescue in read_value'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:21:in `read_value'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:16:in `initialize'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `new'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `build'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:223:in `build'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:78:in `block in def_attribute'
(erb):14:in `<main>'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/erb_renderer.rb:25:in `render!'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/erb_renderer.rb:32:in `safe_render!'
/Users/ash/src/gitlab/gdks/gdk1/lib/tasks/config.rake:160:in `block in <top (required)>'
Caused by:
KeyError: key not found: "__network_mode_host"
Did you mean? "network_mode_host"
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:22:in `fetch'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:22:in `read_value'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/base.rb:16:in `initialize'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `new'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_type/builder.rb:20:in `build'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:223:in `build'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/config_settings.rb:78:in `block in def_attribute'
(erb):14:in `<main>'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/erb_renderer.rb:25:in `render!'
/Users/ash/src/gitlab/gdks/gdk1/lib/gdk/erb_renderer.rb:32:in `safe_render!'
/Users/ash/src/gitlab/gdks/gdk1/lib/tasks/config.rake:160:in `block in <top (required)>'
Tasks: TOP => gitlab-runner-config.toml
(See full trace by running task with --trace)
make: *** [gitlab-runner-config.toml] Error 1
After
$ gdk config get runner.__network_mode_host
❌️ ERROR: runner.network_mode_host is only supported on Linux.
$ make gitlab-runner-config.toml
❌️ ERROR: runner.network_mode_host is only supported on Linux.
make: *** [gitlab-runner-config.toml] Error 1
Merge Request checklist
-
Tests added for new functionality. If not, please raise Issue to follow-up. -
This change is backward compatible. If not, please include steps to communicate to our users. -
Documentation added/updated, if needed. -
gdk doctor
test added, if needed.