Browse Source

fix(script) Fix exception management (#54150)

The management of inexistent options was out of the try-catch
Filippo Pacifici 1 year ago
parent
commit
531c61bbd3

+ 7 - 7
src/sentry/runner/commands/configoptions.py

@@ -156,6 +156,13 @@ def configoptions(ctx, dry_run: bool, file: Optional[str], hide_drift: bool) ->
                 invalid_options.add(key)
             elif not_writable_reason == options.NotWritableReason.DRIFTED:
                 drifted_options.add(key)
+
+            opt = options.lookup_key(key)
+            if not opt.type.test(value):
+                invalid_options.add(key)
+                logger.error(
+                    "Option %s has invalid type. got %s, expected %s.", key, type(value), opt.type
+                )
         except options.UnknownOption:
             invalid_options.add(key)
             logger.error(
@@ -163,13 +170,6 @@ def configoptions(ctx, dry_run: bool, file: Optional[str], hide_drift: bool) ->
                 key,
             )
 
-        opt = options.lookup_key(key)
-        if not opt.type.test(value):
-            invalid_options.add(key)
-            logger.error(
-                "Option %s has invalid type. got %s, expected %s.", key, type(value), opt.type
-            )
-
     ctx.obj["invalid_options"] = invalid_options
     ctx.obj["drifted_options"] = drifted_options
     ctx.obj["hide_drift"] = hide_drift

+ 1 - 0
tests/sentry/runner/commands/badpatch.yaml

@@ -2,3 +2,4 @@ options:
   int_option: 50
   readonly_option: 30
   invalid_type: [1,2,3]
+  inexistent_option: 10

+ 1 - 0
tests/sentry/runner/commands/test_configoptions.py

@@ -215,6 +215,7 @@ class ConfigOptionsTest(CliTestCase):
 
         assert SET_MSG % ("int_option", 50) in rv.output
         assert "Option invalid_type has invalid type." in rv.output
+        assert "Option inexistent_option is not registered." in rv.output
 
         assert not options.isset("readonly_option")
         assert not options.isset("invalid_type")