Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions fire/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def Fire(component=None, command=None, name=None, serialize=None):
raise FireExit(0, component_trace)

# The command succeeded normally; print the result.
_PrintResult(component_trace, verbose=component_trace.verbose, serialize=serialize)
_PrintResult(
component_trace, verbose=component_trace.verbose, serialize=serialize)
result = component_trace.GetResult()
return result

Expand Down Expand Up @@ -247,11 +248,12 @@ def _PrintResult(component_trace, verbose=False, serialize=None):
# and move serialization to its own module.
result = component_trace.GetResult()

# Allow users to modify the return value of the component and provide
# Allow users to modify the return value of the component and provide
# custom formatting.
if serialize:
if not callable(serialize):
raise FireError("serialize argument {} must be empty or callable.".format(serialize))
raise FireError(
'The argument `serialize` must be empty or callable:', serialize)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Consider removing the variable from the error message for security reasons.

Exposing variable content in error messages can lead to security risks, especially if sensitive data is inadvertently logged.

Suggested change
'The argument `serialize` must be empty or callable:', serialize)
raise FireError(
'The argument `serialize` must be empty or callable.')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment helpful?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment type correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the comment area correct?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What type of LLM test could this comment become?

  • 👍 - this comment is really good/important and we should always make it
  • 👎 - this comment is really bad and we should never make it
  • no reaction - don't turn this comment into an LLM test

result = serialize(result)

if value_types.HasCustomStr(result):
Expand Down
15 changes: 8 additions & 7 deletions fire/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,22 @@ def serialize(x):
if isinstance(x, list):
return ', '.join(str(xi) for xi in x)
if isinstance(x, dict):
return ', '.join('{}={!r}'.format(k, v) for k, v in x.items())
return ', '.join('{}={!r}'.format(k, v) for k, v in sorted(x.items()))
if x == 'special':
return ['SURPRISE!!', "I'm a list!"]
return x

ident = lambda x: x

with self.assertOutputMatches(stdout='a, b', stderr=None):
result = core.Fire(ident, command=['[a,b]'], serialize=serialize)
_ = core.Fire(ident, command=['[a,b]'], serialize=serialize)
with self.assertOutputMatches(stdout='a=5, b=6', stderr=None):
result = core.Fire(ident, command=['{a:5,b:6}'], serialize=serialize)
_ = core.Fire(ident, command=['{a:5,b:6}'], serialize=serialize)
with self.assertOutputMatches(stdout='asdf', stderr=None):
result = core.Fire(ident, command=['asdf'], serialize=serialize)
with self.assertOutputMatches(stdout="SURPRISE!!\nI'm a list!\n", stderr=None):
result = core.Fire(ident, command=['special'], serialize=serialize)
_ = core.Fire(ident, command=['asdf'], serialize=serialize)
with self.assertOutputMatches(
stdout="SURPRISE!!\nI'm a list!\n", stderr=None):
_ = core.Fire(ident, command=['special'], serialize=serialize)
with self.assertRaises(core.FireError):
core.Fire(ident, command=['asdf'], serialize=55)

Expand Down