
import generate as gen

commands = {}

def cmd_func(name):
    def _cmd_func(f):
        commands.setdefault(name, f)
        return f
    return _cmd_func

@cmd_func('get-latest-rev')
def get_latest_rev(args):
    return "%s %s" % (gen.success('( )', gen.string('test')),
                      gen.success('12'))

def handle_command(msg):
    command = msg[0]
    args = msg [1]

    if command not in commands:
        return gen.failure(gen.list('12',
                                    gen.string('unknown command: %s' % command),
                                    gen.string('commands.py'), '0'))

    return commands[command](args)


import generate as gen

commands = {}

def cmd_func(name):
    def _cmd_func(f):
        commands.setdefault(name, f)
        return f
    return _cmd_func

@cmd_func('get-latest-rev')
def get_latest_rev(args):
    return "%s %s" % (gen.success('( )', gen.string('test')),
                      gen.success('12'))

def handle_command(msg):
    command = msg[0]
    args = msg [1]

    if command not in commands:
        return gen.failure(gen.list('210001',
                                    gen.string("Unknown command '%s'" % command),
                                    gen.string('commands.py'), '0'))

    return commands[command](args)

Use the real unknown command err-code
Use the real unknown command err-code

Using the real unknown command error code means that the client
actually understands the error and behaves appropriately.

  
  import generate as gen
  
  commands = {}
  
  def cmd_func(name):
      def _cmd_func(f):
          commands.setdefault(name, f)
          return f
      return _cmd_func
  
  @cmd_func('get-latest-rev')
  def get_latest_rev(args):
      return "%s %s" % (gen.success('( )', gen.string('test')),
                        gen.success('12'))
  
  def handle_command(msg):
      command = msg[0]
      args = msg [1]
  
      if command not in commands:
-         return gen.failure(gen.list('12',
+         return gen.failure(gen.list('210001',
-                                     gen.string('unknown command: %s' % command),
+                                     gen.string("Unknown command '%s'" % command),
                                      gen.string('commands.py'), '0'))
  
      return commands[command](args)
  
Use the real unknown command err-code
## Code Before:

import generate as gen

commands = {}

def cmd_func(name):
    def _cmd_func(f):
        commands.setdefault(name, f)
        return f
    return _cmd_func

@cmd_func('get-latest-rev')
def get_latest_rev(args):
    return "%s %s" % (gen.success('( )', gen.string('test')),
                      gen.success('12'))

def handle_command(msg):
    command = msg[0]
    args = msg [1]

    if command not in commands:
        return gen.failure(gen.list('12',
                                    gen.string('unknown command: %s' % command),
                                    gen.string('commands.py'), '0'))

    return commands[command](args)

## Instruction:
Use the real unknown command err-code
## Code After:

import generate as gen

commands = {}

def cmd_func(name):
    def _cmd_func(f):
        commands.setdefault(name, f)
        return f
    return _cmd_func

@cmd_func('get-latest-rev')
def get_latest_rev(args):
    return "%s %s" % (gen.success('( )', gen.string('test')),
                      gen.success('12'))

def handle_command(msg):
    command = msg[0]
    args = msg [1]

    if command not in commands:
        return gen.failure(gen.list('210001',
                                    gen.string("Unknown command '%s'" % command),
                                    gen.string('commands.py'), '0'))

    return commands[command](args)
