Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console-err-msg #430

Merged
merged 8 commits into from
Oct 14, 2021
Merged

console-err-msg #430

merged 8 commits into from
Oct 14, 2021

Conversation

Rispectech
Copy link
Contributor

In order to prevent redundancy in each component, I created a new js file (errorfunc.js) which contains all the error functions I used apart from occasional exceptions where it couldn't be used

in errorfunc.js , checkMissingValueObj checks whether the values are present or not

@vercel
Copy link

vercel bot commented Oct 2, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/saadpasta/developer-folio/Sis1cT2Xy6miZfydqQGGSvVqrAyv
✅ Preview: https://developer-folio-git-fork-rispectech-console-error-msg-saadpasta.vercel.app

Copy link
Collaborator

@kartikcho kartikcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a quick look over the changes and it seems you understood the issues incorrectly. The issue #212 says to add error messages for only third party components, i.e GitHub repos, Twitter embed, podcasts and the GitHub contact components.

Throwing errors for missing fields would be counter intuitive as we also want users to have the option to keep fields blank if they wish to do so. Lots of errors in the console blowing up in people's face will make them feel they're doing something wrong when it's just an empty field.

Also looking at the implementation, you're using logs instead of errors which isn't the best way to warn someone.

@@ -16,6 +20,9 @@ export default function EducationCard({school}) {
: null;
};
const {isDark} = useContext(StyleContext);

if (!school.logo)
console.log(`Image of schoolName ${school.name} is not available`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep this in as it seems helpful but change it to console.error('Image of ${school.name} is missing in education section');

@@ -0,0 +1,48 @@
//function to check whether the url is correct
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably need to scrap all of this code and it's usage in other components as it isn't what is required currently :(

@Rispectech
Copy link
Contributor Author

Rispectech commented Oct 3, 2021

I took a quick look over the changes and it seems you understood the issues incorrectly. The issue #212 says to add error messages for only third party components, i.e GitHub repos, Twitter embed, podcasts and the GitHub contact components.

Throwing errors for missing fields would be counter intuitive as we also want users to have the option to keep fields blank if they wish to do so. Lots of errors in the console blowing up in people's face will make them feel they're doing something wrong when it's just an empty field.

Also looking at the implementation, you're using logs instead of errors which isn't the best way to warn someone.

okay, so you want the error using throw error instead of log. right will do this one
second right using the error function for all the components intuitive so fix this as well

@Rispectech
Copy link
Contributor Author

Rispectech commented Oct 3, 2021

I have converted the console messages in third party components to error messages and removed them from the rest
errorfunc.js deleted as well
@kartikcho please check and review the changes
thanks

Copy link
Collaborator

@kartikcho kartikcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of changes to make so please see all review comments and double check to not leave any changes not relevant to the PR.
Also, run prettier and fix all the code formatting inconsistencies.

return;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this extra line

var win = window.open(url, "_blank");
win.focus();
}

return (
<div onClick={() => openUrlInNewTab(blog.url)}>
<div onClick={() => openUrlInNewTab(blog.url, blog.img, blog.title)}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would work incorrectly to log image path so we don't need to pass blog.img here.

))
: null;
if (!descBullets) return null;
else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need an if-else statement here since it will be evaluated to null by the ternary operator if it's false. Adding this would be an unnecessary extra step so let's revert this.

@@ -7,6 +7,7 @@ export default function EducationCard({school}) {
const imgRef = createRef();

const GetDescBullets = ({descBullets}) => {
if (!descBullets) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as ExperienceCard.js, let's revert this change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed reverting these changes.

if (!url) {
console.log(`URl for ${name} not found `);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra space at the end of the string and use 'URL'

@@ -6,6 +6,10 @@ import StyleContext from "../../contexts/StyleContext";

export default function Podcast() {
const {isDark} = useContext(StyleContext);

if (!podcastSection)
throw new Error("Podcast objects for Podcast section is missing");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick to throwing errors only in console throughout the app so use console.error

Copy link
Contributor Author

@Rispectech Rispectech Oct 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will revert this but I wanted to discuss whether if throwing an error is a better choice than using the console. error since we are using map function and it is better to let the user know that the object is missing since we will get an error anyway if it is undefined and we using the map

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return just below this line (L13) if the object is undefined or display is set to false so it will be covered.

@@ -21,7 +22,7 @@ export default function Profile() {
if (result.ok) {
return result.json();
}
console.error(result);
throw new Error("Couldn't fetch profile.json data");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need any error here since we're catching it below

openSource.showGithubProfile = "false";
throw new Error(
`${error} occured when tried to fetch profile data`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this and go back to using console.error

@@ -50,6 +50,11 @@ export default function Projects() {
<h1 className="project-title">Open Source Projects</h1>
<div className="repo-cards-div-main">
{repo.map((v, i) => {
if (!v) {
throw new Error(
`Github Object for repository number : ${i + 1} is undefined`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See object v in GithubRepoCard and use repository name instead of number in the error.
Also, use console.error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I tried doing this but it complains you can not access the .node.id property when u pass props to the GithubRepocard so we have to display the error before we pass the props
Secondly, the name is present in the object v in the node key so I don't think there is any other way to get the name of the repo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant display repo name using v.node.name here instead of repo id if possible, since that would make the message more verbose.

@@ -24,6 +24,9 @@ export default function Twitter() {
if (!twitterDetails.display) {
return null;
}
if (!twitterDetails.userName) {
throw new Error("Twitter details for twitter section are missing ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • use console.error
  • change error to 'Twitter username for Twitter section is missing'
  • Remove extra space at the end of string

@Rispectech
Copy link
Contributor Author

sorry @kartikcho for being such a pain making you request changes again and again
I got confused with throw and console when you last commented so made these mistakes so sorry for that
I have made the changes so please review and check
thanks

Copy link
Collaborator

@kartikcho kartikcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're almost there and can get this in soon, just need to address a few more comments. Make sure to not leave any extra lines committed and run formatting just to be extra sure.

Also, don't feel bad if your PR is taking more rounds of reviews, we're all learning here!

@@ -7,6 +7,7 @@ export default function EducationCard({school}) {
const imgRef = createRef();

const GetDescBullets = ({descBullets}) => {
if (!descBullets) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed reverting these changes.

@@ -18,6 +18,7 @@ export default function ExperienceCard({cardInfo, isDark}) {
}

const GetDescBullets = ({descBullets, isDark}) => {
if (!descBullets) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this too, remove this as we're checking for descBullets using the ternary operator below.

@@ -6,11 +6,13 @@ import emoji from "react-easy-emoji";
import {Fade} from "react-reveal";

export default function GithubProfileCard({prof}) {
if (!prof) throw new Error("GithubProfileObject missing ");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all changes from this file then @Rispectech

if (!url) {
console.log(`Url in ${name} is undefined`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Overlooked this 'URL' :P

@@ -7,6 +7,7 @@ const renderLoader = () => <Loading />;
const GithubProfileCard = lazy(() =>
import("../../components/githubProfileCard/GithubProfileCard")
);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line committed

openSource.showGithubProfile = "false";
console.error(`${error} occured when trying to fetch profile`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error that would be caught here would be a complete error message in itself so we don't need to wrap it in a message here as it would make the error log confusing.

@@ -50,6 +50,11 @@ export default function Projects() {
<h1 className="project-title">Open Source Projects</h1>
<div className="repo-cards-div-main">
{repo.map((v, i) => {
if (!v) {
throw new Error(
`Github Object for repository number : ${i + 1} is undefined`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant display repo name using v.node.name here instead of repo id if possible, since that would make the message more verbose.

@@ -24,6 +24,9 @@ export default function Twitter() {
if (!twitterDetails.display) {
return null;
}
if (!twitterDetails.userName) {
console.error("Twitter username for twitter section are missing");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: 'Twitter username for Twitter section is missing'

@Rispectech
Copy link
Contributor Author

Rispectech commented Oct 9, 2021

We're almost there and can get this in soon, just need to address a few more comments. Make sure to not leave any extra lines committed and run formatting just to be extra sure.

Also, don't feel bad if your PR is taking more rounds of reviews, we're all learning here!

i don't mind getting reviews on my pr it just shows where I am lacking. it's just that constantly disturbing you is bugging me 😅

@Rispectech
Copy link
Contributor Author

I have made most of the changes along with the repo name but I am sure it won't work as if v is undefined then v.node won't be accessible as we will get the error "cant access property node of undefined" it was same in case of v.node.id that's why I
used the repository number.
here is a working sample
Screenshot from 2021-10-09 09-21-42
but I case of repository number it doesn't give this error and console the error with the rest of the messages

Copy link
Collaborator

@kartikcho kartikcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small changes to address and also revert the GitHub repo error message to how it was before, using repo index.
Almost there!

@@ -11,6 +11,7 @@ export default function GithubProfileCard({prof}) {
} else {
prof.hireable = "No";
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this extra line

@@ -6,6 +6,10 @@ import StyleContext from "../../contexts/StyleContext";

export default function Podcast() {
const {isDark} = useContext(StyleContext);

if (!podcastSection)
console.error("Podcast objects for Podcast section is missing");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change this to 'podcastSection' object for Podcast section is missing to make it a bit nicer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if I am understanding right, you want the variable podcastSection which was in the if statement in the string right ? .
assuming so it won't work since this if block fires only when podcastSection is null so if we pull it in the string
the output we get would be
"null / undefined objects for Podcast section is missing "

Screenshot from 2021-10-13 10-24-39
here is the working sample
I have made the changes though

@@ -26,6 +30,11 @@ export default function Podcast() {
</div>
<div className="podcast-main-div">
{podcastSection.podcast.map((podcastLink, i) => {
if (!podcastLink) {
console.log(
`podcast link for ${podcastSection.title} is missing`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Use a capital P at the start of the sentence :P

@@ -50,6 +50,9 @@ export default function Projects() {
<h1 className="project-title">Open Source Projects</h1>
<div className="repo-cards-div-main">
{repo.map((v, i) => {
if (!v) {
console.error(`Github Object for ${v.node.name} is undefined`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this should work but I'm just speculating without digging deep into it.
Revert it the previous error message you proposed using repo index for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I know that my solution was messy and not informative but I couldn't figure out how to access the name since v is undefined. i would like to better than this but cant figure out how to do so

@Rispectech
Copy link
Contributor Author

Just a couple of small changes to address and also revert the GitHub repo error message to how it was before, using repo index. Almost there!

I have done these changes and I wasn't so sure about the GitHub repo error so if are talking about the error messages in getRepoData in project.js in container, I have done that
thanks

@@ -6,6 +6,10 @@ import StyleContext from "../../contexts/StyleContext";

export default function Podcast() {
const {isDark} = useContext(StyleContext);

if (!podcastSection)
console.error(`${podcastSection} object for Podcast section is missing`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being confusing before, I didn't mean to print the object in the console, just the variable name.
So it should look like console.error('podcastSection object for Podcast section is missing');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. i have done the changes

Copy link
Collaborator

@kartikcho kartikcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to go, thanks!

@kartikcho kartikcho merged commit cdb9998 into saadpasta:master Oct 14, 2021
@kartikcho
Copy link
Collaborator

@allcontributors add @Rispectech for code

@allcontributors
Copy link
Contributor

@kartikcho

I've put up a pull request to add @Rispectech! 🎉

Mehranmzn pushed a commit to Mehranmzn/mehranmzn.github.io that referenced this pull request Sep 13, 2024
* console-err-msg

* fixed console to error message

* requested changes

* .

* githubprofilecard-revert

* required changes

* changes-required

* changes-required
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants