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

chore: Disallows unknown fields in JSON sent by Rust. #4753

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion cli/cmd/turbo/main.go
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/vercel/turbo/cli/internal/cmd"
"github.com/vercel/turbo/cli/internal/turbostate"
Expand All @@ -17,7 +18,10 @@ func main() {

executionStateString := os.Args[1]
var executionState turbostate.ExecutionState
err := json.Unmarshal([]byte(executionStateString), &executionState)
decoder := json.NewDecoder(strings.NewReader(executionStateString))
decoder.DisallowUnknownFields()

err := decoder.Decode(&executionState)
if err != nil {
fmt.Printf("Error unmarshalling execution state: %v\n Execution state string: %v\n", err, executionStateString)
os.Exit(1)
Expand Down
12 changes: 9 additions & 3 deletions crates/turborepo-lib/src/cli.rs
Expand Up @@ -67,6 +67,7 @@ pub enum EnvMode {
#[clap(arg_required_else_help = true)]
pub struct Args {
#[clap(long, global = true)]
#[serde(skip)]
pub version: bool,
#[clap(long, global = true)]
#[serde(skip)]
Expand All @@ -75,6 +76,7 @@ pub struct Args {
pub skip_infer: bool,
/// Disable the turbo update notification
#[clap(long, global = true)]
#[serde(skip)]
pub no_update_notifier: bool,
/// Override the endpoint for API calls
#[clap(long, global = true, value_parser)]
Expand Down Expand Up @@ -116,12 +118,16 @@ pub struct Args {
/// verbosity
#[clap(flatten)]
pub verbosity: Verbosity,
#[clap(long, global = true, hide = true)]
/// Force a check for a new version of turbo
#[clap(long, global = true, hide = true)]
#[serde(skip)]
pub check_for_update: bool,
#[clap(long = "__test-run", global = true, hide = true)]
pub test_run: bool,
#[clap(flatten, next_help_heading = "Run Arguments")]
// We don't serialize this because by the time we're calling
// Go, we've moved it to the command field as a Command::Run
#[serde(skip)]
pub run_args: Option<RunArgs>,
#[clap(subcommand)]
pub command: Option<Command>,
Expand Down Expand Up @@ -209,8 +215,8 @@ impl Args {
process::exit(0);
}
};
// --version flag doesn't work with ignore_errors in clap, so we have to handle
// it manually
// We have to override the --version flag because we use `get_version`
// instead of a hard-coded version or the crate version
if clap_args.version {
println!("{}", get_version());
process::exit(0);
Expand Down