messages.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../../_version.js';
  8. export const messages = {
  9. 'invalid-value': ({ paramName, validValueDescription, value }) => {
  10. if (!paramName || !validValueDescription) {
  11. throw new Error(`Unexpected input to 'invalid-value' error.`);
  12. }
  13. return (`The '${paramName}' parameter was given a value with an ` +
  14. `unexpected value. ${validValueDescription} Received a value of ` +
  15. `${JSON.stringify(value)}.`);
  16. },
  17. 'not-an-array': ({ moduleName, className, funcName, paramName }) => {
  18. if (!moduleName || !className || !funcName || !paramName) {
  19. throw new Error(`Unexpected input to 'not-an-array' error.`);
  20. }
  21. return (`The parameter '${paramName}' passed into ` +
  22. `'${moduleName}.${className}.${funcName}()' must be an array.`);
  23. },
  24. 'incorrect-type': ({ expectedType, paramName, moduleName, className, funcName, }) => {
  25. if (!expectedType || !paramName || !moduleName || !funcName) {
  26. throw new Error(`Unexpected input to 'incorrect-type' error.`);
  27. }
  28. const classNameStr = className ? `${className}.` : '';
  29. return (`The parameter '${paramName}' passed into ` +
  30. `'${moduleName}.${classNameStr}` +
  31. `${funcName}()' must be of type ${expectedType}.`);
  32. },
  33. 'incorrect-class': ({ expectedClassName, paramName, moduleName, className, funcName, isReturnValueProblem, }) => {
  34. if (!expectedClassName || !moduleName || !funcName) {
  35. throw new Error(`Unexpected input to 'incorrect-class' error.`);
  36. }
  37. const classNameStr = className ? `${className}.` : '';
  38. if (isReturnValueProblem) {
  39. return (`The return value from ` +
  40. `'${moduleName}.${classNameStr}${funcName}()' ` +
  41. `must be an instance of class ${expectedClassName}.`);
  42. }
  43. return (`The parameter '${paramName}' passed into ` +
  44. `'${moduleName}.${classNameStr}${funcName}()' ` +
  45. `must be an instance of class ${expectedClassName}.`);
  46. },
  47. 'missing-a-method': ({ expectedMethod, paramName, moduleName, className, funcName, }) => {
  48. if (!expectedMethod ||
  49. !paramName ||
  50. !moduleName ||
  51. !className ||
  52. !funcName) {
  53. throw new Error(`Unexpected input to 'missing-a-method' error.`);
  54. }
  55. return (`${moduleName}.${className}.${funcName}() expected the ` +
  56. `'${paramName}' parameter to expose a '${expectedMethod}' method.`);
  57. },
  58. 'add-to-cache-list-unexpected-type': ({ entry }) => {
  59. return (`An unexpected entry was passed to ` +
  60. `'workbox-precaching.PrecacheController.addToCacheList()' The entry ` +
  61. `'${JSON.stringify(entry)}' isn't supported. You must supply an array of ` +
  62. `strings with one or more characters, objects with a url property or ` +
  63. `Request objects.`);
  64. },
  65. 'add-to-cache-list-conflicting-entries': ({ firstEntry, secondEntry }) => {
  66. if (!firstEntry || !secondEntry) {
  67. throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`);
  68. }
  69. return (`Two of the entries passed to ` +
  70. `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` +
  71. `${firstEntry} but different revision details. Workbox is ` +
  72. `unable to cache and version the asset correctly. Please remove one ` +
  73. `of the entries.`);
  74. },
  75. 'plugin-error-request-will-fetch': ({ thrownErrorMessage }) => {
  76. if (!thrownErrorMessage) {
  77. throw new Error(`Unexpected input to ` + `'plugin-error-request-will-fetch', error.`);
  78. }
  79. return (`An error was thrown by a plugins 'requestWillFetch()' method. ` +
  80. `The thrown error message was: '${thrownErrorMessage}'.`);
  81. },
  82. 'invalid-cache-name': ({ cacheNameId, value }) => {
  83. if (!cacheNameId) {
  84. throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
  85. }
  86. return (`You must provide a name containing at least one character for ` +
  87. `setCacheDetails({${cacheNameId}: '...'}). Received a value of ` +
  88. `'${JSON.stringify(value)}'`);
  89. },
  90. 'unregister-route-but-not-found-with-method': ({ method }) => {
  91. if (!method) {
  92. throw new Error(`Unexpected input to ` +
  93. `'unregister-route-but-not-found-with-method' error.`);
  94. }
  95. return (`The route you're trying to unregister was not previously ` +
  96. `registered for the method type '${method}'.`);
  97. },
  98. 'unregister-route-route-not-registered': () => {
  99. return (`The route you're trying to unregister was not previously ` +
  100. `registered.`);
  101. },
  102. 'queue-replay-failed': ({ name }) => {
  103. return `Replaying the background sync queue '${name}' failed.`;
  104. },
  105. 'duplicate-queue-name': ({ name }) => {
  106. return (`The Queue name '${name}' is already being used. ` +
  107. `All instances of backgroundSync.Queue must be given unique names.`);
  108. },
  109. 'expired-test-without-max-age': ({ methodName, paramName }) => {
  110. return (`The '${methodName}()' method can only be used when the ` +
  111. `'${paramName}' is used in the constructor.`);
  112. },
  113. 'unsupported-route-type': ({ moduleName, className, funcName, paramName }) => {
  114. return (`The supplied '${paramName}' parameter was an unsupported type. ` +
  115. `Please check the docs for ${moduleName}.${className}.${funcName} for ` +
  116. `valid input types.`);
  117. },
  118. 'not-array-of-class': ({ value, expectedClass, moduleName, className, funcName, paramName, }) => {
  119. return (`The supplied '${paramName}' parameter must be an array of ` +
  120. `'${expectedClass}' objects. Received '${JSON.stringify(value)},'. ` +
  121. `Please check the call to ${moduleName}.${className}.${funcName}() ` +
  122. `to fix the issue.`);
  123. },
  124. 'max-entries-or-age-required': ({ moduleName, className, funcName }) => {
  125. return (`You must define either config.maxEntries or config.maxAgeSeconds` +
  126. `in ${moduleName}.${className}.${funcName}`);
  127. },
  128. 'statuses-or-headers-required': ({ moduleName, className, funcName }) => {
  129. return (`You must define either config.statuses or config.headers` +
  130. `in ${moduleName}.${className}.${funcName}`);
  131. },
  132. 'invalid-string': ({ moduleName, funcName, paramName }) => {
  133. if (!paramName || !moduleName || !funcName) {
  134. throw new Error(`Unexpected input to 'invalid-string' error.`);
  135. }
  136. return (`When using strings, the '${paramName}' parameter must start with ` +
  137. `'http' (for cross-origin matches) or '/' (for same-origin matches). ` +
  138. `Please see the docs for ${moduleName}.${funcName}() for ` +
  139. `more info.`);
  140. },
  141. 'channel-name-required': () => {
  142. return (`You must provide a channelName to construct a ` +
  143. `BroadcastCacheUpdate instance.`);
  144. },
  145. 'invalid-responses-are-same-args': () => {
  146. return (`The arguments passed into responsesAreSame() appear to be ` +
  147. `invalid. Please ensure valid Responses are used.`);
  148. },
  149. 'expire-custom-caches-only': () => {
  150. return (`You must provide a 'cacheName' property when using the ` +
  151. `expiration plugin with a runtime caching strategy.`);
  152. },
  153. 'unit-must-be-bytes': ({ normalizedRangeHeader }) => {
  154. if (!normalizedRangeHeader) {
  155. throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
  156. }
  157. return (`The 'unit' portion of the Range header must be set to 'bytes'. ` +
  158. `The Range header provided was "${normalizedRangeHeader}"`);
  159. },
  160. 'single-range-only': ({ normalizedRangeHeader }) => {
  161. if (!normalizedRangeHeader) {
  162. throw new Error(`Unexpected input to 'single-range-only' error.`);
  163. }
  164. return (`Multiple ranges are not supported. Please use a single start ` +
  165. `value, and optional end value. The Range header provided was ` +
  166. `"${normalizedRangeHeader}"`);
  167. },
  168. 'invalid-range-values': ({ normalizedRangeHeader }) => {
  169. if (!normalizedRangeHeader) {
  170. throw new Error(`Unexpected input to 'invalid-range-values' error.`);
  171. }
  172. return (`The Range header is missing both start and end values. At least ` +
  173. `one of those values is needed. The Range header provided was ` +
  174. `"${normalizedRangeHeader}"`);
  175. },
  176. 'no-range-header': () => {
  177. return `No Range header was found in the Request provided.`;
  178. },
  179. 'range-not-satisfiable': ({ size, start, end }) => {
  180. return (`The start (${start}) and end (${end}) values in the Range are ` +
  181. `not satisfiable by the cached response, which is ${size} bytes.`);
  182. },
  183. 'attempt-to-cache-non-get-request': ({ url, method }) => {
  184. return (`Unable to cache '${url}' because it is a '${method}' request and ` +
  185. `only 'GET' requests can be cached.`);
  186. },
  187. 'cache-put-with-no-response': ({ url }) => {
  188. return (`There was an attempt to cache '${url}' but the response was not ` +
  189. `defined.`);
  190. },
  191. 'no-response': ({ url, error }) => {
  192. let message = `The strategy could not generate a response for '${url}'.`;
  193. if (error) {
  194. message += ` The underlying error is ${error}.`;
  195. }
  196. return message;
  197. },
  198. 'bad-precaching-response': ({ url, status }) => {
  199. return (`The precaching request for '${url}' failed` +
  200. (status ? ` with an HTTP status of ${status}.` : `.`));
  201. },
  202. 'non-precached-url': ({ url }) => {
  203. return (`createHandlerBoundToURL('${url}') was called, but that URL is ` +
  204. `not precached. Please pass in a URL that is precached instead.`);
  205. },
  206. 'add-to-cache-list-conflicting-integrities': ({ url }) => {
  207. return (`Two of the entries passed to ` +
  208. `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` +
  209. `${url} with different integrity values. Please remove one of them.`);
  210. },
  211. 'missing-precache-entry': ({ cacheName, url }) => {
  212. return `Unable to find a precached response in ${cacheName} for ${url}.`;
  213. },
  214. 'cross-origin-copy-response': ({ origin }) => {
  215. return (`workbox-core.copyResponse() can only be used with same-origin ` +
  216. `responses. It was passed a response with origin ${origin}.`);
  217. },
  218. 'opaque-streams-source': ({ type }) => {
  219. const message = `One of the workbox-streams sources resulted in an ` +
  220. `'${type}' response.`;
  221. if (type === 'opaqueredirect') {
  222. return (`${message} Please do not use a navigation request that results ` +
  223. `in a redirect as a source.`);
  224. }
  225. return `${message} Please ensure your sources are CORS-enabled.`;
  226. },
  227. };