prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  __main__ top-level script shadowing ImportError
  Given `main.py`:
  ```python
  import nonexistent  # assuming this is... non-existent
  from sanic import Sanic, response
  
  
  app = Sanic(__name__)
  
  
  @app.route('/')
  async def index(request):
      return response.html('<p>Hello</p>')
  ```
  
  When we try to import something non-existent, exception `ImportError` will be thrown,
  [line 38 of __main__.py](https://github.com/channelcat/sanic/blob/5fd62098bd2f2722876a0873d5856d70046d3889/sanic/__main__.py#L38) does not preserve the exception, reporting preset message (what's provided on commandline) instead.  This is what we will get:
  
  ```
  python -m sanic main.app
  No module named main found.
    Example File: project/sanic_server.py -> app
    Example Module: project.sanic_server.app
  ```
  
  It is very hard to find the true cause if the import statement that failed is, let's say, buried three levels of modules deep, for example.
  
  </issue>
  <code>
  [start of sanic/__main__.py]
  1 from argparse import ArgumentParser
  2 from importlib import import_module
  3 
  4 from sanic.log import log
  5 from sanic.app import Sanic
  6 
  7 if __name__ == "__main__":
  8     parser = ArgumentParser(prog='sanic')
  9     parser.add_argument('--host', dest='host', type=str, default='127.0.0.1')
  10     parser.add_argument('--port', dest='port', type=int, default=8000)
  11     parser.add_argument('--cert', dest='cert', type=str,
  12                         help='location of certificate for SSL')
  13     parser.add_argument('--key', dest='key', type=str,
  14                         help='location of keyfile for SSL.')
  15     parser.add_argument('--workers', dest='workers', type=int, default=1, )
  16     parser.add_argument('--debug', dest='debug', action="store_true")
  17     parser.add_argument('module')
  18     args = parser.parse_args()
  19 
  20     try:
  21         module_parts = args.module.split(".")
  22         module_name = ".".join(module_parts[:-1])
  23         app_name = module_parts[-1]
  24 
  25         module = import_module(module_name)
  26         app = getattr(module, app_name, None)
  27         if not isinstance(app, Sanic):
  28             raise ValueError("Module is not a Sanic app, it is a {}.  "
  29                              "Perhaps you meant {}.app?"
  30                              .format(type(app).__name__, args.module))
  31         if args.cert is not None or args.key is not None:
  32             ssl = {'cert': args.cert, 'key': args.key}
  33         else:
  34             ssl = None
  35 
  36         app.run(host=args.host, port=args.port,
  37                 workers=args.workers, debug=args.debug, ssl=ssl)
  38     except ImportError:
  39         log.error("No module named {} found.\n"
  40                   "  Example File: project/sanic_server.py -> app\n"
  41                   "  Example Module: project.sanic_server.app"
  42                   .format(module_name))
  43     except ValueError as e:
  44         log.error("{}".format(e))
  45
  [end of sanic/__main__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/sanic/__main__.py b/sanic/__main__.py
  --- a/sanic/__main__.py
  +++ b/sanic/__main__.py
  @@ -35,10 +35,10 @@
   
           app.run(host=args.host, port=args.port,
                   workers=args.workers, debug=args.debug, ssl=ssl)
  -    except ImportError:
  +    except ImportError as e:
           log.error("No module named {} found.\n"
                     "  Example File: project/sanic_server.py -> app\n"
                     "  Example Module: project.sanic_server.app"
  -                  .format(module_name))
  +                  .format(e.name))
       except ValueError as e:
           log.error("{}".format(e))
  
verification_info: {"golden_diff": "diff --git a/sanic/__main__.py b/sanic/__main__.py\n--- a/sanic/__main__.py\n+++ b/sanic/__main__.py\n@@ -35,10 +35,10 @@\n \n         app.run(host=args.host, port=args.port,\n                 workers=args.workers, debug=args.debug, ssl=ssl)\n-    except ImportError:\n+    except ImportError as e:\n         log.error(\"No module named {} found.\\n\"\n                   \"  Example File: project/sanic_server.py -> app\\n\"\n                   \"  Example Module: project.sanic_server.app\"\n-                  .format(module_name))\n+                  .format(e.name))\n     except ValueError as e:\n         log.error(\"{}\".format(e))\n", "issue": "__main__ top-level script shadowing ImportError\nGiven `main.py`:\r\n```python\r\nimport nonexistent  # assuming this is... non-existent\r\nfrom sanic import Sanic, response\r\n\r\n\r\napp = Sanic(__name__)\r\n\r\n\r\n@app.route('/')\r\nasync def index(request):\r\n    return response.html('<p>Hello</p>')\r\n```\r\n\r\nWhen we try to import something non-existent, exception `ImportError` will be thrown,\r\n[line 38 of __main__.py](https://github.com/channelcat/sanic/blob/5fd62098bd2f2722876a0873d5856d70046d3889/sanic/__main__.py#L38) does not preserve the exception, reporting preset message (what's provided on commandline) instead.  This is what we will get:\r\n\r\n```\r\npython -m sanic main.app\r\nNo module named main found.\r\n  Example File: project/sanic_server.py -> app\r\n  Example Module: project.sanic_server.app\r\n```\r\n\r\nIt is very hard to find the true cause if the import statement that failed is, let's say, buried three levels of modules deep, for example.\n", "before_files": [{"content": "from argparse import ArgumentParser\nfrom importlib import import_module\n\nfrom sanic.log import log\nfrom sanic.app import Sanic\n\nif __name__ == \"__main__\":\n    parser = ArgumentParser(prog='sanic')\n    parser.add_argument('--host', dest='host', type=str, default='127.0.0.1')\n    parser.add_argument('--port', dest='port', type=int, default=8000)\n    parser.add_argument('--cert', dest='cert', type=str,\n                        help='location of certificate for SSL')\n    parser.add_argument('--key', dest='key', type=str,\n                        help='location of keyfile for SSL.')\n    parser.add_argument('--workers', dest='workers', type=int, default=1, )\n    parser.add_argument('--debug', dest='debug', action=\"store_true\")\n    parser.add_argument('module')\n    args = parser.parse_args()\n\n    try:\n        module_parts = args.module.split(\".\")\n        module_name = \".\".join(module_parts[:-1])\n        app_name = module_parts[-1]\n\n        module = import_module(module_name)\n        app = getattr(module, app_name, None)\n        if not isinstance(app, Sanic):\n            raise ValueError(\"Module is not a Sanic app, it is a {}.  \"\n                             \"Perhaps you meant {}.app?\"\n                             .format(type(app).__name__, args.module))\n        if args.cert is not None or args.key is not None:\n            ssl = {'cert': args.cert, 'key': args.key}\n        else:\n            ssl = None\n\n        app.run(host=args.host, port=args.port,\n                workers=args.workers, debug=args.debug, ssl=ssl)\n    except ImportError:\n        log.error(\"No module named {} found.\\n\"\n                  \"  Example File: project/sanic_server.py -> app\\n\"\n                  \"  Example Module: project.sanic_server.app\"\n                  .format(module_name))\n    except ValueError as e:\n        log.error(\"{}\".format(e))\n", "path": "sanic/__main__.py"}]}