Skip to content

Commit 8c415fd

Browse files
Fix incorrect formatting and broken links in help messages (#323)
* Fix incorrect formatting and broken links in help messages * Fix log handler level
1 parent f7b4ff1 commit 8c415fd

File tree

6 files changed

+51
-49
lines changed

6 files changed

+51
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixed
66

7+
* exceptions: Fixed incorrect formatting and broken links in help messages.
78
* index: Fixed crash when the only index in config is `head`.
89
* index: Fixed fetching originations during initial sync.
910

scripts/extract_reference.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/print_help.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from unittest.mock import MagicMock
2+
import dipdup.exceptions as exc
3+
import dipdup.models as models
4+
5+
example_exceptions = (
6+
exc.DipDupError(),
7+
exc.DatasourceError('Everything is broken', 'tzkt_mainnet'),
8+
exc.ConfigurationError('Invalid config'),
9+
exc.DatabaseConfigurationError('Invalid model', models.Head),
10+
exc.MigrationRequiredError('1.1', '1.2'),
11+
exc.ReindexingRequiredError(
12+
exc.ReindexingReason.rollback,
13+
{'foo': 'bar', 'asdf': 'qwer'},
14+
),
15+
exc.InitializationRequiredError('Missing handler'),
16+
exc.HandlerImportError('demo_tzbtz.handlers.on_mint', 'on_mint'),
17+
exc.ContractAlreadyExistsError(MagicMock(), 'test', 'tz1deadbeafdeadbeafdeadbeafdeadbeafdeadbeaf'),
18+
exc.IndexAlreadyExistsError(MagicMock(), 'test'),
19+
exc.InvalidDataError(models.BigMapData, 'foo', {'foo': 'bar'}),
20+
exc.CallbackError('demo_tzbtc.handlers.on_mint', ValueError('foo')),
21+
exc.CallbackTypeError('handler', 'on_mint', 'foo', int, str),
22+
exc.HasuraError('Invalid query'),
23+
)
24+
25+
for e in example_exceptions:
26+
print(f'{e.__class__.__name__}: {e}')
27+
print()
28+
print(e.help())
29+
print(exc._tab)

src/dipdup/configs/logging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ formatters:
55
format: "%(levelname)-8s %(name)-20s %(message)s"
66
handlers:
77
console:
8-
level: INFO
8+
level: DEBUG
99
formatter: brief
1010
class: logging.StreamHandler
1111
stream: ext://sys.stdout

src/dipdup/configs/warning.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ formatters:
55
format: "%(levelname)-8s %(name)-20s %(message)s"
66
handlers:
77
console:
8-
level: WARNING
8+
level: DEBUG
99
formatter: brief
1010
class: logging.StreamHandler
1111
stream: ext://sys.stdout

src/dipdup/exceptions.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,10 @@ def __str__(self) -> str:
4646
return self.__doc__
4747

4848
def _help(self) -> str:
49-
# FIXME: Indentation hell
50-
prefix = '\n' + ' ' * 14
51-
context = prefix.join(str(self.args))
52-
if context:
53-
context = '{prefix}{context}\n'.format(prefix=prefix, context=context)
54-
5549
return """
5650
An unexpected error has occurred!
57-
{context}
58-
Please file a bug report at https://github.com/dipdup-net/dipdup/issues and attach the following:
5951
60-
* `dipdup.yml` config. Make sure to remove sensitive information.
61-
* Reasonable amount of logs before the crash.
52+
Please file a bug report at https://github.com/dipdup-net/dipdup/issues
6253
"""
6354

6455
def help(self) -> str:
@@ -79,7 +70,7 @@ def _help(self) -> str:
7970
return f"""
8071
`{self.datasource}` datasource returned an error: {self.msg}
8172
82-
Most likely, this is a DipDup bug. Please file a bug report at https://github.com/dipdup-net/dipdup/issues
73+
Please file a bug report at https://github.com/dipdup-net/dipdup/issues
8374
"""
8475

8576

@@ -93,7 +84,7 @@ def _help(self) -> str:
9384
return f"""
9485
{self.msg}
9586
96-
DipDup config reference: https://docs.dipdup.net/config-file-reference
87+
DipDup config reference: https://docs.dipdup.net/config
9788
"""
9889

9990

@@ -107,11 +98,11 @@ def _help(self) -> str:
10798
return f"""
10899
{self.msg}
109100
110-
Model: `{self.model.__class__.__name__}`
101+
Model: `{self.model._meta._model.__name__}`
111102
Table: `{self.model._meta.db_table}`
112103
113104
Tortoise ORM examples: https://tortoise-orm.readthedocs.io/en/latest/examples.html
114-
DipDup config reference: https://docs.dipdup.net/config-file-reference/database
105+
DipDup config reference: https://docs.dipdup.net/config/database
115106
"""
116107

117108

@@ -177,6 +168,8 @@ def _help(self) -> str:
177168

178169
@dataclass(repr=False)
179170
class InitializationRequiredError(DipDupError):
171+
"""Project initialization required"""
172+
180173
message: str
181174

182175
def _help(self) -> str:
@@ -198,23 +191,22 @@ class HandlerImportError(DipDupError):
198191
obj: Optional[str] = None
199192

200193
def _help(self) -> str:
201-
what = f'`{self.obj}` from ' if self.obj else ''
194+
what = f'`{self.obj}` from' if self.obj else ''
202195
return f"""
203196
Failed to import {what} module `{self.module}`.
204197
205198
Reasons in order of possibility:
206199
207-
1. `init` command was not called after modifying config
208-
2. Name of handler module and handler function inside it don't match
209-
2. Invalid `package` config value, reusing name of existing package
210-
3. Something's wrong with PYTHONPATH env variable
211-
200+
1. `init` command was not called after modifying config
201+
2. Name of handler module and handler function inside it don't match
202+
3. Invalid `package` config value, reusing name of existing package
203+
4. Something's wrong with `PYTHONPATH` env variable
212204
"""
213205

214206

215207
@dataclass(repr=False)
216208
class ContractAlreadyExistsError(DipDupError):
217-
"""Attemp to add a contract with alias or address which is already in use"""
209+
"""Attempt to add a contract with alias or address already in use"""
218210

219211
ctx: Any
220212
name: str
@@ -238,7 +230,7 @@ def _help(self) -> str:
238230

239231
@dataclass(repr=False)
240232
class IndexAlreadyExistsError(DipDupError):
241-
"""Attemp to add an index with alias which is already in use"""
233+
"""Attemp to add an index with an alias already in use"""
242234

243235
ctx: Any
244236
name: str
@@ -292,9 +284,9 @@ class CallbackError(DipDupError):
292284

293285
def _help(self) -> str:
294286
return f"""
295-
`{self.module}` callback execution failed.
287+
`{self.module}` callback execution failed:
296288
297-
{self.exc.__class__.__name__}{self.exc}
289+
{self.exc.__class__.__name__}: {self.exc}
298290
299291
Eliminate the reason of failure and restart DipDup.
300292
"""
@@ -331,7 +323,9 @@ class HasuraError(DipDupError):
331323

332324
def _help(self) -> str:
333325
return f"""
334-
Failed to configure Hasura: {self.msg}
326+
Failed to configure Hasura:
327+
328+
{self.msg}
335329
336330
Check out Hasura logs for more information.
337331

0 commit comments

Comments
 (0)