Browse Source

Fixes issue #501 and improves an error message

I was getting an error from my supervisor config due to having %(process_num)s
in the command field of a program. This is supposed to work, but apparently some
refactoring broke it accidentally. The reason is that we call saneget outside
the for-loop that sets the process_num value, and so the expansion fails.

This also improves the "Format string contains names which cannot be expanded"
error message, so that it displays a list of expansions variables that are
available.
Gustavo Carneiro 10 năm trước cách đây
mục cha
commit
d2481dde06
1 tập tin đã thay đổi với 16 bổ sung12 xóa
  1. 16 12
      supervisor/options.py

+ 16 - 12
supervisor/options.py

@@ -876,11 +876,6 @@ class ServerOptions(Options):
         if umask is not None:
             umask = octal_type(umask)
 
-        command = get(section, 'command', None)
-        if command is None:
-            raise ValueError(
-                'program section %s does not specify a command' % section)
-
         process_name = process_or_group_name(
             get(section, 'process_name', '%(program_name)s', do_expand=False))
 
@@ -937,10 +932,15 @@ class ServerOptions(Options):
                         'rollover, set maxbytes > 0 to avoid filling up '
                         'filesystem unintentionally' % (section, n))
 
+            command = get(section, 'command', expansions=expansions)
+            if command is None:
+                raise ValueError(
+                    'program section %s does not specify a command' % section)
+
             pconfig = klass(
                 self,
                 name=expand(process_name, expansions, 'process_name'),
-                command=expand(command, expansions, 'command'),
+                command=command,
                 directory=directory,
                 umask=umask,
                 priority=priority,
@@ -2040,14 +2040,18 @@ class SignalReceiver:
 def expand(s, expansions, name):
     try:
         return s % expansions
-    except KeyError:
+    except KeyError as ex:
+        available = list(expansions.keys())
+        available.sort()
         raise ValueError(
-            'Format string %r for %r contains names which cannot be '
-            'expanded' % (s, name))
-    except:
+            'Format string %r for %r contains names (%s) which cannot be '
+            'expanded. Available names: %s' %
+            (s, name, str(ex), ", ".join(available)))
+    except Exception as ex:
         raise ValueError(
-            'Format string %r for %r is badly formatted' % (s, name)
-            )
+            'Format string %r for %r is badly formatted: %s' %
+            (s, name, str(ex))
+        )
 
 def environ_expansions():
     """Return dict of environment variables, suitable for use in string