Skip to content

labelValueProvider type cast problem in resolvePath #1532

@bashleigh

Description

@bashleigh

Hello, I wanted to make a log of this issue I've had that is related to this package. It looks like the function labelValueProvider is defined as returning either string or undefined. Later the returned value of labelValueProvider is being cast as a string and then length is being using against the same value.

export const resolvedPath = (
resolvedPath: string,
input: unknown,
memberName: string,
labelValueProvider: () => string | undefined,
uriLabel: string,
isGreedyLabel: boolean
): string => {
if (input != null && (input as Record<string, unknown>)[memberName] !== undefined) {
const labelValue = labelValueProvider() as string;
if (labelValue.length <= 0) {

I've not looked too much into this problem as I have some compiling complexities making this issue difficult to trace. In my issue I'm having a problem on line 16 where Cannot read properties of null (reading 'length') is the result. So I'm thinking labelValueProvider returns string, undefined or null?

I'm having this problem where @smithy/core is being used by @aws-sdk/client-cloudfront and my request looks as follows

const cloudfrontClient = new CloudFrontClient({})

const distroResult = await this.cloudfrontClient.send(
  new GetDistributionCommand({
    Id: 'myCloudfrontDistroId', // could potentially be undefined?
  }),
)

granted, my problem could be my implementation and not recieving the correct error?

I'm going to dig deeper into my issue, it would appear for now that the issue was introduced from our updating to ^3.675.0 potentially and persists in my upadting to ^3.750.0. However, regardless I would recommend the condition be improved for type safety and avoid the type casting.

const labelValue = labelValueProvider();
if (!labelValue || labelValue.length <= 0) {

I'm using node 18 within a lambda and heavily compiling the code using tsup and I reckon the problem could be a result of the complexity of compiling the typescript with tsup and configs. Wanted to bring the type casting issue to your attention though. Hopefully this makes sense and is helpful to someone

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions