Skip to content

Commit 6368498

Browse files
stainless-app[bot]batuhan
authored andcommitted
fix: fix for test cases with newlines in YAML and better error reporting
1 parent b30b746 commit 6368498

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

pkg/cmd/flagoptions.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,20 @@ func flagOptions(
227227

228228
if len(pipeData) > 0 {
229229
var bodyData any
230-
if err := yaml.Unmarshal(pipeData, &bodyData); err == nil {
231-
if bodyMap, ok := bodyData.(map[string]any); ok {
232-
if flagMap, ok := requestContents.Body.(map[string]any); ok {
233-
maps.Copy(bodyMap, flagMap)
234-
requestContents.Body = bodyMap
235-
} else {
236-
bodyData = requestContents.Body
237-
}
238-
} else if flagMap, ok := requestContents.Body.(map[string]any); ok && len(flagMap) > 0 {
239-
return nil, fmt.Errorf("Cannot merge flags with a body that is not a map: %v", bodyData)
230+
if err := yaml.Unmarshal(pipeData, &bodyData); err != nil {
231+
return nil, fmt.Errorf("Failed to parse piped data as YAML/JSON:\n%w", err)
232+
}
233+
if bodyMap, ok := bodyData.(map[string]any); ok {
234+
if flagMap, ok := requestContents.Body.(map[string]any); ok {
235+
maps.Copy(bodyMap, flagMap)
236+
requestContents.Body = bodyMap
240237
} else {
241-
requestContents.Body = bodyData
238+
bodyData = requestContents.Body
242239
}
240+
} else if flagMap, ok := requestContents.Body.(map[string]any); ok && len(flagMap) > 0 {
241+
return nil, fmt.Errorf("Cannot merge flags with a body that is not a map: %v", bodyData)
242+
} else {
243+
requestContents.Body = bodyData
243244
}
244245
}
245246
}

0 commit comments

Comments
 (0)