Azure/azure-storage-js

err.code.toUpperCase is not a function

Closed this issue · 9 comments

Which service(blob, file, queue, table) does this issue concern?

blob

Which version of the SDK was used?

latest

What's the Node.js/Browser version?

chrome

What problem was encountered?

RetryPolicy../node_modules/@azure/storage-blob/dist-esm/lib/policies/RetryPolicy.js.RetryPolicy.shouldRetry
TypeError: err.code.toUpperCase is not a function

Steps to reproduce the issue?

use in a another library and install into main project

Have you found a mitigation/solution?

no

@tomer-eproval Is this a random issue or always happens on your side? What's the specific Chrome version? Please share a more detailed re-produce steps or sample codes.

Will close this issue as long time no response, fell free to re-open if you have further questions.

@XiaoningLiu
I observed this issue today. In my case, if the SAS token does not have '?' at start, i.e if it is
sv=xxxxx instead of ?sv=xxxxx. It throws the above mentioned error.

@SarveshDeshmukh Interesting. What's your SDK version, Node.js or browser runtime? Can you provide a code sample?

@XiaoningLiu Hello, sorry for the late reply.
The version I am using is 10.3.0. And I am using browser runtime. uploadBrowserDataToBlockBlob()
Here's the code sample:

  • Function to get the relevant info from backend:
/**
* Gets all the information required for Blob transfer using `uploadBrowserDataToBlockBlob()`
*/
  getSasTokenAndBlobInfo() {
    return {
      sasToken: '?sv=xxxx',
      storageAccountName: 'xxxx',
      containerName: 'xxxx',
      blobName: '',
    };
  }
  • Function that does the upload job using uploadBrowserDataToBlockBlob()
  /**
   * Uploads a file to Azure Storage
   * @param file file to be uploaded
   * @returns Promise containing blob upload response
   */
  uploadAttachment(file: File): Promise<void | BlobUploadCommonResponse> {
    const blockBlobURL = this.getBlobBlockURL(file.name);
    const aborter = Aborter.none;
    return uploadBrowserDataToBlockBlob(
      aborter,
      new Blob([file], { type: file.type }),
      blockBlobURL,
      {
        blockSize: BLOB_TRANSFER_CONFIG.BLOCK_SIZE * 1024 * 1024, // BLOCK_SIZE MB block size
        parallelism: BLOB_TRANSFER_CONFIG.CONCURRENCY, // Concurrency of parallel uploading. Must be > 0
        progress: ev => {
          console.log('Uploaded so far', ev.loadedBytes);
        },
      },
    ).then(
      response => {
        if (response.errorCode == null) {
          blockBlobURL.setHTTPHeaders(aborter, { blobContentType: file.type });
          console.log('Complete');
        } else {
          throw new Error(response.errorCode);
        }
        return response;
      },
      err => {
        console.log(err);
      },
    );
  }
  • Function that returns me the BlobBlockURL:
/**
   * @returns the url needed for upload and download operation
   * @param fileName file name for which the url is needed
   */
  private getBlobBlockURL(fileName: string): BlockBlobURL {
    const sasAndBlobInfo = this.getSasTokenAndBlobInfo();
    const pipeline = StorageURL.newPipeline(new AnonymousCredential(), {
      retryOptions: { maxTries: 4 }, // Retry options
      telemetry: { value: 'HighLevelSample V1.0.0' }, // Customized telemetry string
    });
    const serviceURL = new ServiceURL(
      `https://${sasAndBlobInfo.storageAccountName}.blob.core.windows.net${
        sasAndBlobInfo.sasToken
      }`,
      pipeline,
    );

    const containerURL = ContainerURL.fromServiceURL(
      serviceURL,
      sasAndBlobInfo.containerName,
    );

    // Create a blob
    const blobName = fileName;
    const blobURL = BlobURL.fromContainerURL(containerURL, blobName);

    return BlockBlobURL.fromBlobURL(blobURL);
  }

So, when I remove ? from the SAS token. The above error is observed.

Thanks! I believe we should improve the error handling!

Any update on this please?

@SarveshDeshmukh Confirmed this is a bug. Should be able to fix in next release in late June. BTW, contribution is also welcome.

This is fixed in latest releases from 10.4.0, see https://www.npmjs.com/package/@azure/storage-blob