@@ -119,6 +119,10 @@ const (
119119 ScsRepoWarningMsg = "SCS scan warning: Unable to start Scorecard scan due to missing required flags, please include in the ast-cli arguments: " +
120120 "--scs-repo-url your_repo_url --scs-repo-token your_repo_token"
121121 ScsScorecardUnsupportedHostWarningMsg = "SCS scan warning: Unable to run Scorecard scanner due to unsupported repo host. Currently, Scorecard can only run on GitHub Cloud repos."
122+
123+ jsonExt = ".json"
124+ xmlExt = ".xml"
125+ sbomScanTypeErrMsg = "--sbom-only flag is only supported with scan type: sca"
122126)
123127
124128var (
@@ -1342,15 +1346,15 @@ func validateScanTypes(cmd *cobra.Command, jwtWrapper wrappers.JWTWrapper, featu
13421346
13431347 scanTypes = strings .Split (userScanTypes , "," )
13441348
1345- // sbom check
1349+ // check scan-types, when sbom-only flag is used
13461350 if isSbomScan {
13471351 if len (scanTypes ) > 1 {
1348- err = errors .Errorf ("while using sbom-only flag only the sca scan type is allowed." )
1352+ err = errors .Errorf (sbomScanTypeErrMsg )
13491353 return err
13501354 }
13511355
13521356 if scanTypes [0 ] != "sca" {
1353- err = errors .Errorf ("while using sbom-only flag only the sca scan type is allowed." )
1357+ err = errors .Errorf (sbomScanTypeErrMsg )
13541358 return err
13551359 }
13561360 }
@@ -1688,10 +1692,10 @@ func getUploadURLFromSource(cmd *cobra.Command, uploadsWrapper wrappers.UploadsW
16881692 sbomFile , _ := cmd .Flags ().GetString (commonParams .SourcesFlag )
16891693 isValid , err := isValidJSONOrXML (sbomFile )
16901694 if err != nil {
1691- return "" , "" , errors .New (err . Error () )
1695+ return "" , "" , errors .Wrapf (err , "%s: Input in bad format" , failedCreating )
16921696 }
16931697 if ! isValid {
1694- return "" , "" , errors .New ( "Provide a correct JSON/XML file" )
1698+ return "" , "" , errors .Wrapf ( err , "%s: Input in bad format" , failedCreating )
16951699 }
16961700 zipFilePath , err = util .CompressFile (sbomFile , "sbomFileCompress" , directoryCreationPrefix )
16971701 } else {
@@ -3144,7 +3148,7 @@ func createMinimalZipFile() (string, error) {
31443148
31453149func isValidJSONOrXML (path string ) (bool , error ) {
31463150 ext := strings .ToLower (filepath .Ext (path ))
3147- if ext != ".json" && ext != ".xml" {
3151+ if ext != jsonExt && ext != xmlExt {
31483152 return false , nil
31493153 }
31503154
@@ -3154,15 +3158,15 @@ func isValidJSONOrXML(path string) (bool, error) {
31543158 }
31553159
31563160 switch ext {
3157- case ".json" :
3161+ case jsonExt :
31583162 var js interface {}
31593163 if err := json .Unmarshal (data , & js ); err != nil {
3160- return false , nil // Invalid JSON
3164+ return false , fmt . Errorf ( "invalid JSON format. %w" , err ) // Invalid JSON
31613165 }
3162- case ".xml" :
3166+ case xmlExt :
31633167 var x interface {}
31643168 if err := xml .Unmarshal (data , & x ); err != nil {
3165- return false , nil // Invalid XML
3169+ return false , fmt . Errorf ( "invalid XML format.%w" , err ) // Invalid XML
31663170 }
31673171 default :
31683172 return false , nil
0 commit comments