Getting started creating a new event source (Reddit)

Dylan Sather (Pipedream) : pd dev deploys the components to your account (as does pd deploy). Does that answer your question or were you asking something different?

SERW2039 : I was asking something different. Let’s say I am on a new filesystem and i don’t have the source code for my components. So, is there a command I can use within the pd-cli to get, download, push to my local filesytem the file system structure of my component (the component files, and any folder hierachy they are organized)?

Dylan Sather (Pipedream) : ah, currently not, but I expect some of this might come as we improve the CLI / API

SERW2039 : okay, so for now i am pulling from my forked repo the base component code. just wonderd if there was something integrated on the pd cli. all right.

SERW2039 : , here asking a what is the general practice when handling errors in the source? I just noticed a source i am coding broke with 404 because it traied to accessed an url that didn’t existed, the url is formed in part with a input prop. Is it common i.e. in this case to prompt the user to check if the prop entered exists?

Dylan Sather (Pipedream) : in this case, did you just enter a value with a typo in the prop, or was the value missing altogether?

SERW2039 : a value with a typo.

SERW2039 : i missed a trailing character in the intended value

Dylan Sather (Pipedream) : gotcha. What prop?

SERW2039 : the subreddit name, in a source that polls for new link in subreddits. the subreddit name in this case is an input prop

Dylan Sather (Pipedream) : I see. I’d recommend catching the 404 error specifically (i.e. try / catch the error) and throwing a new error that tells the user something like: “We encountered a 404 error trying to fetch links for ${this.subreddit}. Please check the subreddit name and try again”. Pseudocode:

try {
  await makeRequest()
} catch (err) {
  if (err.response.status) {
    throw new Error("text from above")
  }
  throw err;
}

Dylan Sather (Pipedream) : in general, we plan to add better validation in the future, but if there are common errors you encounter, it’s good to give the user as much information as possible

SERW2039 : ok, i will follow the recommendation. yeah at first i was thinking if maybe there was a hook for errors, or otherwise something addressing validations. thx for input

SERW2039 : is it good practice to reference the api documentation related to actions, sources developed in the PD component model? what’s recommended here? Asking since for actions so far have been including the associated api endpoint, and for sources i added the api docs’s endpoint entry in the source file, or in the app file point to the general api documentation.

Dylan Sather (Pipedream) : I personally follow these rules:

• I like to link to the main API docs at the top of the app file
• If there’s a really nuanced API call, or something I’ve implemented in code whose purpose is best explained by linking to a specific doc, I do it inline. e.g. we had to implement rate limiting for Shopify, so I linked to their rate limiting docs in the relevant method.
It’s not necessary to link to the docs for every method. As long as you link to the docs once at the top of the app file, that provides the necessary context.

SERW2039 : one question that just popped. It’s regarding optional props. As we have discussed elsewhere, and as per PD Component docs, props have a “optional"property”, when set to true, the user is not required to set the prop’s value. L’et’s say a prop has only one option “given” (in the prop definition we would have my_prop: [“given”], and we also include the optional property to true. How can the user skip selecting the only value available, and leave it blank, and null/undefined?

Dylan Sather (Pipedream) : if the prop only has one value, can you just set it within the code and not make it a prop?

SERW2039 : that would be best if the prop has one value, but since the prop is optional, what if the user doesn’t want to define it (and it would translate into a null value for that prop? (in another instance, i let the user capture the prop freely, compare to the only valid value if correct the value was keep i’d keep it, and otherwise default for undefined)

SERW2039 : or in other words, since the prop is optional how can the user leverage from this and just avoid setting value to the prop? how can he/she skip entering a value for a prop?

Dylan Sather (Pipedream) : if the prop is optional, the user won’t be forced to enter it in the UI. In the code, you can check for the presence of the prop before you use it. Does that work in your case?