Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Improve warnings
Browse files Browse the repository at this point in the history
Add warnings for when indices are not continuous from 0
  • Loading branch information
manthey committed Oct 14, 2024
1 parent 8c753e7 commit e47d4b6
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions slicer_cli_web/ctk_cli_adjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def parse(cls, elementTree): # noqa
if self.index is not None:
self.index = int(self.index)

if self.default:
if self.default is not None:
try:
self.default = self.parseValue(self.default)
except ValueError as e:
Expand All @@ -124,7 +124,7 @@ def parse(cls, elementTree): # noqa
not self.isVector() and not self.isExternalType() and
self.channel != 'output'):
ctk_cli.module.logger.warning(
'No <default> provided for element of type <%s>', self.typ)
'No <default> provided for element of type <%s> (%s)', self.typ, self.name)

if self.typ.endswith('-enumeration'):
try:
Expand Down Expand Up @@ -158,6 +158,26 @@ def _ctkCliParse(cls, elementTree): # noqa

ctk_cli.module.CLIParameters.parse = _ctkCliParse

_orig_CLIModule_init = ctk_cli.CLIModule.__init__


def _CLIModule_init(self, path=None, env=None, stream=None):
ret = _orig_CLIModule_init(self, path, env, stream)
indices = set()
for param in self.parameters():
if param.index is not None:
idx = int(param.index)
if idx in indices:
ctk_cli.module.logger.warning('Parameter index %d used multiple times', idx)

Check warning on line 171 in slicer_cli_web/ctk_cli_adjustment.py

View check run for this annotation

Codecov / codecov/patch

slicer_cli_web/ctk_cli_adjustment.py#L171

Added line #L171 was not covered by tests
indices.add(idx)
if len(indices) and (min(indices) < 0 or max(indices) >= len(indices)):
ctk_cli.module.logger.warning('Parameter indices are not continuous from 0 upwards')

return ret


ctk_cli.CLIModule.__init__ = _CLIModule_init
CLIModule = ctk_cli.CLIModule


__all__ = ['CLIModule']

0 comments on commit e47d4b6

Please sign in to comment.