Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

nil messages are not translated #1267

Closed
Zambito1 opened this issue Feb 11, 2025 · 5 comments
Closed

nil messages are not translated #1267

Zambito1 opened this issue Feb 11, 2025 · 5 comments
Assignees
Labels
defect Suspected defect such as a bug or regression

Comments

@Zambito1
Copy link
Contributor

Observed behavior

If you run nats sub with --translate and receive an empty message, the empty message is not piped to --translate. For example:

nats sub foo --translate='wc -c'

And then

nats pub foo bar
nats pub foo ''

will yield

07:21:35 Subscribing on foo 
[#1] Received on "foo"
3

[#2] Received on "foo"
nil body

Expected behavior

nats sub with --translate='wc -c' should yield 0 when receiving an empty message.

Server and client version

cli: v0.1.2-0.20250122082047-856d2dcf4340
server: 2.10.22

Host environment

Client host: GNU Guix

Steps to reproduce

  • nats sub foo --translace='wc -c'
  • nats pub foo ''
  • observe nil body rather than 0
@Zambito1 Zambito1 added the defect Suspected defect such as a bug or regression label Feb 11, 2025
@ripienaar
Copy link
Collaborator

hmm, not sure we can safely assume all translators will handle nil inputs?

@Zambito1
Copy link
Contributor Author

Right now error exit codes are reported when using --translate and the translator fails.

nats sub foo --translate='false' --raw 2>/dev/null
nats pub foo bar

output of the sub:

""
Error while translating msg body: exit status 1

This seems to me like reasonable behavior when running --translate with a translator fails on nil input.

@ripienaar
Copy link
Collaborator

OK, we'll fix that

ploubser added a commit to ploubser/natscli that referenced this issue Feb 13, 2025
ploubser added a commit to ploubser/natscli that referenced this issue Feb 13, 2025
ploubser added a commit to ploubser/natscli that referenced this issue Feb 13, 2025
ripienaar added a commit that referenced this issue Feb 13, 2025
(#1267) Don't print empty message string when --translate is passed
@ripienaar
Copy link
Collaborator

@Zambito1 we took a stab at this, do you want to see how main works for you now?

@Zambito1
Copy link
Contributor Author

@ripienaar main works for me now, thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

3 participants