From 719893f23850172d224720e6d1257586179ac895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 12 Jul 2024 17:16:00 +0100 Subject: [PATCH] cue: use Value.Err in examples using Compile APIs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Context.CompileString docs say: The returned Value will represent an error, accessible through Err, if any error occurred. Our two examples involving these APIs did not check for an error. This can be OK if the user is sure an error won't happen, but in general that's not a safe assumption to make. Do the safer and recommended error check in the examples. Signed-off-by: Daniel Martí Change-Id: I1dd758d275f457db9eadc9aa6bf0faf7805fdb2b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197696 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Matthew Sackman --- cue/examplecompile_test.go | 4 ++++ cue/examples_test.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cue/examplecompile_test.go b/cue/examplecompile_test.go index 6abb8589dcc..47831751978 100644 --- a/cue/examplecompile_test.go +++ b/cue/examplecompile_test.go @@ -16,6 +16,7 @@ package cue_test import ( "fmt" + "log" "cuelang.org/go/cue" "cuelang.org/go/cue/cuecontext" @@ -29,6 +30,9 @@ func ExampleContext() { b: 3 "a+b": a + b `) + if err := v.Err(); err != nil { + log.Fatal(err) + } p("lookups") p("a: %v", v.LookupPath(cue.ParsePath("a"))) diff --git a/cue/examples_test.go b/cue/examples_test.go index fa841e414e0..65c2d4fe87f 100644 --- a/cue/examples_test.go +++ b/cue/examples_test.go @@ -16,6 +16,7 @@ package cue_test import ( "fmt" + "log" "os" "cuelang.org/go/cue" @@ -87,6 +88,9 @@ d: #C ` v := ctx.CompileString(file) + if err := v.Err(); err != nil { + log.Fatal(err) + } a := v.LookupPath(cue.ParsePath("a")) fmt.Println("a allows:")