88 "strings"
99
1010 "github.com/larksuite/cli/extension/fileio"
11- "github.com/larksuite/cli/internal/output"
1211 "github.com/larksuite/cli/shortcuts/common"
1312)
1413
@@ -51,11 +50,15 @@ const maxBodyFileSize = 32 * 1024 * 1024 // 32 MB
5150func validateBodyFileMutex (bodyFlag , bodyFile string , validatePath func (string ) error ) error {
5251 bodyEmpty := strings .TrimSpace (bodyFlag ) == ""
5352 if ! bodyEmpty && bodyFile != "" {
54- return output .ErrValidation ("--body and --body-file are mutually exclusive; pass exactly one" )
53+ return mailValidationError ("--body and --body-file are mutually exclusive; pass exactly one" ).
54+ WithParams (
55+ mailInvalidParam ("--body" , "mutually exclusive with --body-file" ),
56+ mailInvalidParam ("--body-file" , "mutually exclusive with --body" ),
57+ )
5558 }
5659 if bodyFile != "" {
5760 if err := validatePath (bodyFile ); err != nil {
58- return output . ErrValidation ("--body-file: %v" , err )
61+ return mailValidationParamError ("--body-file" , "--body-file : %v" , err ). WithCause ( err )
5962 }
6063 }
6164 return nil
@@ -79,7 +82,7 @@ func resolveBodyFromFlags(runtime *common.RuntimeContext) (string, error) {
7982
8083func validateRequiredResolvedBody (body string , hasTemplate bool , message string ) error {
8184 if ! hasTemplate && strings .TrimSpace (body ) == "" {
82- return output . ErrValidation ( message )
85+ return mailValidationError ( "%s" , message )
8386 }
8487 return nil
8588}
@@ -95,15 +98,15 @@ func validateRequiredResolvedBody(body string, hasTemplate bool, message string)
9598func readBodyFile (fio fileio.FileIO , path string ) (string , error ) {
9699 f , err := fio .Open (path )
97100 if err != nil {
98- return "" , output . ErrValidation ( " open --body-file %s: %v" , path , err )
101+ return "" , mailValidationParamError ( "--body-file" , " open --body-file %s: %v" , path , err ). WithCause ( mailInputStatError ( err ) )
99102 }
100103 defer f .Close ()
101104 buf , err := io .ReadAll (io .LimitReader (f , maxBodyFileSize + 1 ))
102105 if err != nil {
103- return "" , output . ErrValidation ( " read --body-file %s: %v" , path , err )
106+ return "" , mailValidationParamError ( "--body-file" , " read --body-file %s: %v" , path , err ). WithCause ( err )
104107 }
105108 if len (buf ) > maxBodyFileSize {
106- return "" , output . ErrValidation ( "--body-file: file exceeds %d MB limit" , maxBodyFileSize / 1024 / 1024 )
109+ return "" , mailValidationParamError ( "--body-file" , "--body-file: file exceeds %d MB limit" , maxBodyFileSize / 1024 / 1024 )
107110 }
108111 return string (buf ), nil
109112}
0 commit comments