Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix issue #20 "unexpected end of JSON input" error #64

Merged
merged 5 commits into from
Jan 27, 2024

Conversation

mdb
Copy link
Contributor

@mdb mdb commented Jan 13, 2024

This fixes issue #20 by correcting the reader.CreateReader logic determining whether to use a reader.FileReader or reader.StdinReader. Previously, in some environments (like GH Actions Ubuntu runners), tf-summarize incorrectly attempted to use a reader.StdinReader, even when an explicit filename argument is provided.

Ideally, tf-summarize would feature automated tests through which I could prove the bug & fix. In absence of such tests, I added a demo GitHub Actions job proving tf-summarize continues to work. However, I'm happy to add real tests (either in this PR, or in a followup PR), if you prefer those, @dineshba (I'm also happy to remove the demo GH Actions job from this PR if you prefer it not clutter .github/workflows/build.yml).

Update: I added 2 additional commits:

  • 40f8d1b ensures the use of a consistent Terraform version when interacting with the example project
  • efdf4db adds an automated test verifying the fix provided by this PR showing that tf-summarize -md plan.json and cat plan.json | tf-summarize -md both continue to work as expected.

Note that #63 shows reproduction of the bug via a similar GitHub Actions-based demo.

This addresses #20 and
ensures input is read from the plan file -- and not via STDIN -- if a
plan file argument is provided.

This also seeks to improve some of the error messaging to be a bit more
clear.
Ideally, tf-summarize would feature a suite of automated tests verifying
its functionality. In absenece of that, this demos the issue #20 fix via
GH Actions.
@mdb mdb marked this pull request as ready for review January 13, 2024 18:54
reader/reader.go Show resolved Hide resolved
.github/workflows/build.yml Outdated Show resolved Hide resolved
- ensure the generation of the `example` directory data is done in a
  consistent, reproducible fashion
- ensure GH Actions uses the same version of TF expected by the `example` directory
- add plan and plan JSON files to source control, for testing purposes
@mdb
Copy link
Contributor Author

mdb commented Jan 22, 2024

👋 Hi @dineshba - Have you been able to take a look at this? I'm curious to hear your thoughts. Thanks!

Copy link
Owner

@dineshba dineshba left a comment

Choose a reason for hiding this comment

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

Can we add tfplan in example folder to .gitignore?

@dineshba
Copy link
Owner

Other than this, all changes good. Really appreciate the effort and the fix 👌

This adds a basic automated test verifying the validity of the issue #20
fix.
Per code review request, @dineshba would prefer this be kept in a
separate file.
@mdb
Copy link
Contributor Author

mdb commented Jan 24, 2024

Can we add tfplan in example folder to .gitignore?

@dineshba Good call; I've removed the example/tfplan file and added it to the .gitignore (I've left example/tfplan.json in place, as this file is used by the automated tests).

@mdb mdb requested a review from dineshba January 24, 2024 20:48
@dineshba dineshba merged commit 29d45b2 into dineshba:main Jan 27, 2024
1 check passed
@mdb mdb deleted the fix-json-parsing branch March 3, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants