@@ -820,9 +820,10 @@ describe("wrangler secret", () => {
820
820
`*/accounts/:accountId/workers/scripts/:scriptName/settings` ,
821
821
( { params } ) => {
822
822
expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
823
- return HttpResponse . json (
824
- returnNetworkError ? null : createFetchResult ( null )
825
- ) ;
823
+ if ( returnNetworkError ) {
824
+ return HttpResponse . error ( ) ;
825
+ }
826
+ return HttpResponse . json ( createFetchResult ( null ) ) ;
826
827
}
827
828
)
828
829
) ;
@@ -994,7 +995,7 @@ describe("wrangler secret", () => {
994
995
await expect ( async ( ) => {
995
996
await runWrangler ( "secret bulk ./secret.json --name script-name" ) ;
996
997
} ) . rejects . toThrowErrorMatchingInlineSnapshot (
997
- `[Error: 🚨 7 secrets failed to upload ]`
998
+ `[TypeError: Failed to fetch ]`
998
999
) ;
999
1000
1000
1001
expect ( std . out ) . toMatchInlineSnapshot ( `
@@ -1004,16 +1005,15 @@ describe("wrangler secret", () => {
1004
1005
1005
1006
🌀 Creating the secrets for the Worker \\"script-name\\"
1006
1007
1007
- Finished processing secrets JSON file:
1008
- ✨ 0 secrets successfully uploaded
1008
+ 🚨 Secrets failed to upload
1009
1009
1010
1010
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
1011
1011
` ) ;
1012
1012
expect ( std . err ) . toMatchInlineSnapshot ( `
1013
- "[31mX [41;31m[[41;97mERROR[41;31m][0m [1m🚨 7 secrets failed to upload [0m
1013
+ "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mFailed to fetch [0m
1014
1014
1015
- "
1016
- ` ) ;
1015
+ "
1016
+ ` ) ;
1017
1017
expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
1018
1018
} ) ;
1019
1019
@@ -1030,7 +1030,7 @@ describe("wrangler secret", () => {
1030
1030
await expect ( async ( ) => {
1031
1031
await runWrangler ( "secret bulk ./secret.json --name script-name" ) ;
1032
1032
} ) . rejects . toThrowErrorMatchingInlineSnapshot (
1033
- `[Error: 🚨 2 secrets failed to upload ]`
1033
+ `[TypeError: Failed to fetch ]`
1034
1034
) ;
1035
1035
1036
1036
expect ( std . out ) . toMatchInlineSnapshot ( `
@@ -1040,19 +1040,78 @@ describe("wrangler secret", () => {
1040
1040
1041
1041
🌀 Creating the secrets for the Worker \\"script-name\\"
1042
1042
1043
- Finished processing secrets JSON file:
1044
- ✨ 0 secrets successfully uploaded
1043
+ 🚨 Secrets failed to upload
1045
1044
1046
1045
[32mIf you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose[0m"
1047
1046
` ) ;
1048
1047
expect ( std . err ) . toMatchInlineSnapshot ( `
1049
- "[31mX [41;31m[[41;97mERROR[41;31m][0m [1m🚨 2 secrets failed to upload [0m
1048
+ "[31mX [41;31m[[41;97mERROR[41;31m][0m [1mFailed to fetch [0m
1050
1049
1051
- "
1052
- ` ) ;
1050
+ "
1051
+ ` ) ;
1053
1052
expect ( std . warn ) . toMatchInlineSnapshot ( `""` ) ;
1054
1053
} ) ;
1055
1054
1055
+ it ( "throws a meaningful error" , async ( ) => {
1056
+ writeFileSync (
1057
+ "secret.json" ,
1058
+ JSON . stringify ( {
1059
+ "secret-name-1" : "secret_text" ,
1060
+ "secret-name-2" : "secret_text" ,
1061
+ } )
1062
+ ) ;
1063
+
1064
+ msw . use (
1065
+ http . get (
1066
+ `*/accounts/:accountId/workers/scripts/:scriptName/settings` ,
1067
+ ( { params } ) => {
1068
+ expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
1069
+
1070
+ return HttpResponse . json ( createFetchResult ( { bindings : [ ] } ) ) ;
1071
+ }
1072
+ ) ,
1073
+ http . patch (
1074
+ `*/accounts/:accountId/workers/scripts/:scriptName/settings` ,
1075
+ ( { params } ) => {
1076
+ expect ( params . accountId ) . toEqual ( "some-account-id" ) ;
1077
+ return HttpResponse . json (
1078
+ createFetchResult ( null , false , [
1079
+ {
1080
+ message : "This is a helpful error" ,
1081
+ code : 1 ,
1082
+ } ,
1083
+ ] )
1084
+ ) ;
1085
+ }
1086
+ )
1087
+ ) ;
1088
+
1089
+ await expect ( async ( ) => {
1090
+ await runWrangler ( "secret bulk ./secret.json --name script-name" ) ;
1091
+ } ) . rejects . toThrowErrorMatchingInlineSnapshot (
1092
+ `[APIError: A request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.]`
1093
+ ) ;
1094
+
1095
+ expect ( std . out ) . toMatchInlineSnapshot ( `
1096
+ "
1097
+ ⛅️ wrangler x.x.x
1098
+ ------------------
1099
+
1100
+ 🌀 Creating the secrets for the Worker \\"script-name\\"
1101
+
1102
+ 🚨 Secrets failed to upload
1103
+
1104
+ [31mX [41;31m[[41;97mERROR[41;31m][0m [1mA request to the Cloudflare API (/accounts/some-account-id/workers/scripts/script-name/settings) failed.[0m
1105
+
1106
+ This is a helpful error [code: 1]
1107
+
1108
+ If you think this is a bug, please open an issue at:
1109
+ [4mhttps://github.com/cloudflare/workers-sdk/issues/new/choose[0m
1110
+
1111
+ "
1112
+ ` ) ;
1113
+ } ) ;
1114
+
1056
1115
it ( "should merge existing bindings and secrets when patching" , async ( ) => {
1057
1116
writeFileSync (
1058
1117
"secret.json" ,
0 commit comments