From 84042acc698d82bfa54391ac6b5c0c34e8dc99a2 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Wed, 23 Jun 2021 17:05:01 -0400 Subject: [PATCH 1/8] Update response wrapping --- stone/backends/js_client.py | 9 ++++++++- stone/backends/js_helpers.py | 4 ++-- stone/backends/tsd_client.py | 9 ++++++++- stone/backends/tsd_helpers.py | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/stone/backends/js_client.py b/stone/backends/js_client.py index a8aa7b17..53d00642 100644 --- a/stone/backends/js_client.py +++ b/stone/backends/js_client.py @@ -45,6 +45,13 @@ help=('Wraps the response in a response class') ) +_cmdline_parser.add_argument( + '--wrap-error-in', + type=str, + default='', + help=('Wraps the error in an error class') +) + _header = """\ // Auto-generated by Stone, do not modify. var routes = {}; @@ -99,7 +106,7 @@ def _generate_route(self, route_schema, namespace, route): fmt_type(route.arg_data_type)) self.emit(' * @returns {Promise.<%s, %s>}' % (return_type, - fmt_error_type(route.error_data_type))) + fmt_error_type(route.error_data_type, self.args.wrap_error_in))) self.emit(' */') if route.arg_data_type.__class__ != Void: diff --git a/stone/backends/js_helpers.py b/stone/backends/js_helpers.py index 25a35dc6..2999c6a9 100644 --- a/stone/backends/js_helpers.py +++ b/stone/backends/js_helpers.py @@ -49,11 +49,11 @@ def fmt_obj(o): return json.dumps(o, indent=2) -def fmt_error_type(data_type): +def fmt_error_type(data_type, wrap_error_in=''): """ Converts the error type into a JSDoc type. """ - return 'Error.<%s>' % fmt_type(data_type) + return '%s.<%s>' % (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type) def fmt_type_name(data_type): diff --git a/stone/backends/tsd_client.py b/stone/backends/tsd_client.py index e79ac090..71f50c21 100644 --- a/stone/backends/tsd_client.py +++ b/stone/backends/tsd_client.py @@ -67,6 +67,13 @@ help=('Wraps the response in a response class') ) +_cmdline_parser.add_argument( + '--wrap-error-in', + type=str, + default='', + help=('Wraps the error in an error class') +) + _cmdline_parser.add_argument( '--import-namespaces', default=False, @@ -169,7 +176,7 @@ def _generate_route(self, namespace, route): self.emit_wrapped_text(self.process_doc(route.doc, self._docf), prefix=' * ') self.emit(' *') self.emit_wrapped_text('When an error occurs, the route rejects the promise with type %s.' - % fmt_error_type(route.error_data_type), prefix=' * ') + % fmt_error_type(route.error_data_type, self.args.wrap_error_in), prefix=' * ') if route.deprecated: self.emit(' * @deprecated') diff --git a/stone/backends/tsd_helpers.py b/stone/backends/tsd_helpers.py index 63889552..778e7a68 100644 --- a/stone/backends/tsd_helpers.py +++ b/stone/backends/tsd_helpers.py @@ -41,13 +41,13 @@ } -def fmt_error_type(data_type, inside_namespace=None): +def fmt_error_type(data_type, inside_namespace=None, wrap_error_in=''): """ Converts the error type into a TypeScript type. inside_namespace should be set to the namespace that the reference occurs in, or None if this parameter is not relevant. """ - return 'Error<%s>' % fmt_type(data_type, inside_namespace) + return '%s<%s>' % (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type, inside_namespace) def fmt_type_name(data_type, inside_namespace=None): """ From 25441a6303275078d6ef05bcb22bd991c0348e90 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Wed, 23 Jun 2021 17:09:38 -0400 Subject: [PATCH 2/8] Update formatting --- stone/backends/js_helpers.py | 2 +- stone/backends/tsd_helpers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stone/backends/js_helpers.py b/stone/backends/js_helpers.py index 2999c6a9..45fb1ca2 100644 --- a/stone/backends/js_helpers.py +++ b/stone/backends/js_helpers.py @@ -53,7 +53,7 @@ def fmt_error_type(data_type, wrap_error_in=''): """ Converts the error type into a JSDoc type. """ - return '%s.<%s>' % (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type) + return '%s.<%s>' % ((wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type)) def fmt_type_name(data_type): diff --git a/stone/backends/tsd_helpers.py b/stone/backends/tsd_helpers.py index 778e7a68..c8b1a65a 100644 --- a/stone/backends/tsd_helpers.py +++ b/stone/backends/tsd_helpers.py @@ -47,7 +47,7 @@ def fmt_error_type(data_type, inside_namespace=None, wrap_error_in=''): inside_namespace should be set to the namespace that the reference occurs in, or None if this parameter is not relevant. """ - return '%s<%s>' % (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type, inside_namespace) + return '%s<%s>' % ((wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type, inside_namespace)) def fmt_type_name(data_type, inside_namespace=None): """ From 89ff4fefdb4cfd5d0c0121e0e0678c881bdb41d0 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Wed, 23 Jun 2021 17:32:51 -0400 Subject: [PATCH 3/8] Fix linter --- stone/backends/tsd_client.py | 3 ++- stone/backends/tsd_helpers.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stone/backends/tsd_client.py b/stone/backends/tsd_client.py index 71f50c21..b8907a23 100644 --- a/stone/backends/tsd_client.py +++ b/stone/backends/tsd_client.py @@ -176,7 +176,8 @@ def _generate_route(self, namespace, route): self.emit_wrapped_text(self.process_doc(route.doc, self._docf), prefix=' * ') self.emit(' *') self.emit_wrapped_text('When an error occurs, the route rejects the promise with type %s.' - % fmt_error_type(route.error_data_type, self.args.wrap_error_in), prefix=' * ') + % fmt_error_type(route.error_data_type, + self.args.wrap_error_in), prefix=' * ') if route.deprecated: self.emit(' * @deprecated') diff --git a/stone/backends/tsd_helpers.py b/stone/backends/tsd_helpers.py index c8b1a65a..b4792ec3 100644 --- a/stone/backends/tsd_helpers.py +++ b/stone/backends/tsd_helpers.py @@ -47,7 +47,10 @@ def fmt_error_type(data_type, inside_namespace=None, wrap_error_in=''): inside_namespace should be set to the namespace that the reference occurs in, or None if this parameter is not relevant. """ - return '%s<%s>' % ((wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type, inside_namespace)) + return '%s<%s>' % ( + (wrap_error_in if (wrap_error_in != '') else 'Error'), + fmt_type(data_type, inside_namespace) + ) def fmt_type_name(data_type, inside_namespace=None): """ From dfd602b91e29410494afe9a24c390ab7d54d699b Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 24 Jun 2021 12:19:49 -0400 Subject: [PATCH 4/8] Fix trailing whitespace --- stone/backends/tsd_client.py | 2 +- stone/backends/tsd_helpers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stone/backends/tsd_client.py b/stone/backends/tsd_client.py index b8907a23..7ff52b9d 100644 --- a/stone/backends/tsd_client.py +++ b/stone/backends/tsd_client.py @@ -176,7 +176,7 @@ def _generate_route(self, namespace, route): self.emit_wrapped_text(self.process_doc(route.doc, self._docf), prefix=' * ') self.emit(' *') self.emit_wrapped_text('When an error occurs, the route rejects the promise with type %s.' - % fmt_error_type(route.error_data_type, + % fmt_error_type(route.error_data_type, self.args.wrap_error_in), prefix=' * ') if route.deprecated: self.emit(' * @deprecated') diff --git a/stone/backends/tsd_helpers.py b/stone/backends/tsd_helpers.py index b4792ec3..d0bce5ce 100644 --- a/stone/backends/tsd_helpers.py +++ b/stone/backends/tsd_helpers.py @@ -48,7 +48,7 @@ def fmt_error_type(data_type, inside_namespace=None, wrap_error_in=''): occurs in, or None if this parameter is not relevant. """ return '%s<%s>' % ( - (wrap_error_in if (wrap_error_in != '') else 'Error'), + (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type, inside_namespace) ) From becc6e11a30368ad8e043a4624a6a35da3ecc9f6 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 24 Jun 2021 14:33:54 -0400 Subject: [PATCH 5/8] Fix per comments --- stone/backends/js_helpers.py | 4 ++-- stone/backends/tsd_client.py | 2 -- stone/backends/tsd_helpers.py | 7 ++----- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/stone/backends/js_helpers.py b/stone/backends/js_helpers.py index 45fb1ca2..bb565d71 100644 --- a/stone/backends/js_helpers.py +++ b/stone/backends/js_helpers.py @@ -49,11 +49,11 @@ def fmt_obj(o): return json.dumps(o, indent=2) -def fmt_error_type(data_type, wrap_error_in=''): +def fmt_error_type(data_type, wrap_error_in='Error'): """ Converts the error type into a JSDoc type. """ - return '%s.<%s>' % ((wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type)) + return '%s.<%s>' % (wrap_error_in, fmt_type(data_type)) def fmt_type_name(data_type): diff --git a/stone/backends/tsd_client.py b/stone/backends/tsd_client.py index 7ff52b9d..5140946c 100644 --- a/stone/backends/tsd_client.py +++ b/stone/backends/tsd_client.py @@ -66,14 +66,12 @@ default='', help=('Wraps the response in a response class') ) - _cmdline_parser.add_argument( '--wrap-error-in', type=str, default='', help=('Wraps the error in an error class') ) - _cmdline_parser.add_argument( '--import-namespaces', default=False, diff --git a/stone/backends/tsd_helpers.py b/stone/backends/tsd_helpers.py index d0bce5ce..d694c53b 100644 --- a/stone/backends/tsd_helpers.py +++ b/stone/backends/tsd_helpers.py @@ -41,16 +41,13 @@ } -def fmt_error_type(data_type, inside_namespace=None, wrap_error_in=''): +def fmt_error_type(data_type, inside_namespace=None, wrap_error_in='Error'): """ Converts the error type into a TypeScript type. inside_namespace should be set to the namespace that the reference occurs in, or None if this parameter is not relevant. """ - return '%s<%s>' % ( - (wrap_error_in if (wrap_error_in != '') else 'Error'), - fmt_type(data_type, inside_namespace) - ) + return '%s<%s>' % (wrap_error_in, fmt_type(data_type, inside_namespace)) def fmt_type_name(data_type, inside_namespace=None): """ From 7eba11fa62862e278e51b6f56451e7d6c621ce91 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 24 Jun 2021 14:37:21 -0400 Subject: [PATCH 6/8] Fix issue --- stone/backends/js_helpers.py | 4 ++-- stone/backends/tsd_helpers.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/stone/backends/js_helpers.py b/stone/backends/js_helpers.py index bb565d71..2999c6a9 100644 --- a/stone/backends/js_helpers.py +++ b/stone/backends/js_helpers.py @@ -49,11 +49,11 @@ def fmt_obj(o): return json.dumps(o, indent=2) -def fmt_error_type(data_type, wrap_error_in='Error'): +def fmt_error_type(data_type, wrap_error_in=''): """ Converts the error type into a JSDoc type. """ - return '%s.<%s>' % (wrap_error_in, fmt_type(data_type)) + return '%s.<%s>' % (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type) def fmt_type_name(data_type): diff --git a/stone/backends/tsd_helpers.py b/stone/backends/tsd_helpers.py index d694c53b..d0bce5ce 100644 --- a/stone/backends/tsd_helpers.py +++ b/stone/backends/tsd_helpers.py @@ -41,13 +41,16 @@ } -def fmt_error_type(data_type, inside_namespace=None, wrap_error_in='Error'): +def fmt_error_type(data_type, inside_namespace=None, wrap_error_in=''): """ Converts the error type into a TypeScript type. inside_namespace should be set to the namespace that the reference occurs in, or None if this parameter is not relevant. """ - return '%s<%s>' % (wrap_error_in, fmt_type(data_type, inside_namespace)) + return '%s<%s>' % ( + (wrap_error_in if (wrap_error_in != '') else 'Error'), + fmt_type(data_type, inside_namespace) + ) def fmt_type_name(data_type, inside_namespace=None): """ From 2fa5973b5217018e2bebb2e648f3cc97596334e0 Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 24 Jun 2021 14:40:24 -0400 Subject: [PATCH 7/8] Fix formatting bug --- stone/backends/js_helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stone/backends/js_helpers.py b/stone/backends/js_helpers.py index 2999c6a9..97b1c104 100644 --- a/stone/backends/js_helpers.py +++ b/stone/backends/js_helpers.py @@ -53,7 +53,10 @@ def fmt_error_type(data_type, wrap_error_in=''): """ Converts the error type into a JSDoc type. """ - return '%s.<%s>' % (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type) + return '%s.<%s>' % ( + (wrap_error_in if (wrap_error_in != '') else 'Error'), + fmt_type(data_type) + ) def fmt_type_name(data_type): From f61f70450f70efbb1918059a518fe11d1a0f5dba Mon Sep 17 00:00:00 2001 From: Brad Rogers Date: Thu, 24 Jun 2021 14:42:55 -0400 Subject: [PATCH 8/8] Fix linter --- stone/backends/js_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stone/backends/js_helpers.py b/stone/backends/js_helpers.py index 97b1c104..571a3e87 100644 --- a/stone/backends/js_helpers.py +++ b/stone/backends/js_helpers.py @@ -54,7 +54,7 @@ def fmt_error_type(data_type, wrap_error_in=''): Converts the error type into a JSDoc type. """ return '%s.<%s>' % ( - (wrap_error_in if (wrap_error_in != '') else 'Error'), + (wrap_error_in if (wrap_error_in != '') else 'Error'), fmt_type(data_type) )