From 8a7a61f05d52edcd18d0b7e12d743b71e302b9e7 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Mon, 29 Jan 2024 23:56:42 +0530 Subject: [PATCH] CI to catch incorrect use of clues (#5144) Catches issues where we use `WC` variant of clues when `ctx` is passed and as well as cases where we don't use WC variant when `ctx` is not passed in. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [x] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * # #### Test Plan - [ ] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- .github/workflows/ci.yml | 14 ++++++++++++++ src/internal/converters/vcf/vcf.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69aaff1e1..79316660f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -518,6 +518,20 @@ jobs: echo "Make sure to propagate errors with clues" exit 1 fi + - name: Check if clues without context are used when context is passed in + run: | + # Using `grep .` as the exit codes are always true for correct grammar + if tree-grepper -q go '((function_declaration (parameter_list . (parameter_declaration (identifier) @_octx)) body: (block (short_var_declaration left: (expression_list (identifier) @_err . ) right: (expression_list (call_expression (argument_list . (identifier) @_ctx)))) . (if_statement (binary_expression) @_exp consequence: (block (return_statement (expression_list (call_expression (selector_expression (call_expression (selector_expression) @clue))) . )))))) (#eq? @_err "err") (#eq? @_octx "ctx") (#eq? @_ctx "ctx") (#eq? @_exp "err != nil") (#match? @clue "^clues\.") (#match? @clue "WC$"))' | grep .; then + echo "Do not use clues.*WC when context is passed in" + exit 1 + fi + - name: Check clues with context is used when context is not passed in + run: | + # Using `grep .` as the exit codes are always true for correct grammar + if tree-grepper -q go '((function_declaration (parameter_list . (parameter_declaration (identifier) @_octx)) body: (block (short_var_declaration left: (expression_list (identifier) @_err . ) right: (expression_list (call_expression (argument_list . (identifier) @_ctx)))) . (if_statement (binary_expression) @_exp consequence: (block (return_statement (expression_list (call_expression (selector_expression (call_expression (selector_expression) @clue))) . )))))) (#eq? @_err "err") (#eq? @_octx "ctx") (#not-eq? @_ctx "ctx") (#eq? @_exp "err != nil") (#match? @clue "^clues\.") (#not-match? @clue "WC$"))' | grep .; then + echo "Use clues.*WC when context is not passed in" + exit 1 + fi # ---------------------------------------------------------------------------------------------------- # --- GitHub Actions Linting ------------------------------------------------------------------------- diff --git a/src/internal/converters/vcf/vcf.go b/src/internal/converters/vcf/vcf.go index 0a6a44b2a..2eee33e60 100644 --- a/src/internal/converters/vcf/vcf.go +++ b/src/internal/converters/vcf/vcf.go @@ -86,7 +86,7 @@ func FromJSON(ctx context.Context, body []byte) (string, error) { data, err := api.BytesToContactable(body) if err != nil { - return "", clues.Wrap(err, "converting to contactable"). + return "", clues.WrapWC(ctx, err, "converting to contactable"). With("body_length", len(body)) }