Skip to content

Commit

Permalink
Merge pull request #66 from pluralsh/klink/fix-error-passing
Browse files Browse the repository at this point in the history
fix: Ensure serializability of errors passed by getStaticProps
  • Loading branch information
dogmar authored Nov 14, 2023
2 parents 68f8194 + 696ea7f commit 2383ec0
Show file tree
Hide file tree
Showing 21 changed files with 98 additions and 125 deletions.
74 changes: 0 additions & 74 deletions cli-readme/README.md

This file was deleted.

15 changes: 8 additions & 7 deletions pages/applications/[repo].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
type RecipesQuery,
type RecipesQueryVariables,
} from '@src/generated/graphqlPlural'
import { combineErrors } from '@src/utils/combineErrors'
import {
type GlobalProps,
propsWithGlobalSettings,
Expand Down Expand Up @@ -478,12 +479,12 @@ export const getStaticProps: GetStaticProps<AppPageProps> = async (context) => {
(appExtras.case_study?.stack_apps as string[]) || []
),
footerVariant: FooterVariant.kitchenSink,
errors: [
...(reposError ? [reposError] : []),
...(stacksError ? [stacksError] : []),
...(repoError ? [repoError] : []),
...(appError ? [appError] : []),
...(faqError ? [faqError] : []),
],
errors: combineErrors([
reposError,
stacksError,
repoError,
appError,
faqError,
]),
})
}
3 changes: 2 additions & 1 deletion pages/careers/hire/[job].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getJobListing, getJobListingSlugs } from '@src/data/getJobListings'
import { type FullJobListingFragment } from '@src/generated/graphqlDirectus'
import { ReadMdContent } from '@src/markdoc/mdParser'
import { type MarkdocPage } from '@src/markdoc/mdSchema'
import { combineErrors } from '@src/utils/combineErrors'
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps'

const PAGE_PARAM_NAME = 'job' as const
Expand Down Expand Up @@ -118,6 +119,6 @@ export const getStaticProps: GetStaticProps<JobPageProps> = async (context) => {
footerVariant: FooterVariant.kitchenSink,
job,
markdoc,
errors: [...(jobError ? [jobError] : [])],
errors: combineErrors([jobError]),
})
}
3 changes: 2 additions & 1 deletion pages/careers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ScrollToLink } from '@src/components/ScrollToLink'
import { CenteredSectionHead } from '@src/components/SectionHeads'
import { getJobListings } from '@src/data/getJobListings'
import { type MinJobListingFragment } from '@src/generated/graphqlDirectus'
import { combineErrors } from '@src/utils/combineErrors'
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps'

import { ValueCard } from '../../src/components/ValueCard'
Expand Down Expand Up @@ -292,6 +293,6 @@ export const getStaticProps = async () => {
'We are a growing team working on interesting problems in the cloud with Kubernetes, Elixir, Go, and React. We’re always interested in hiring new talent!',
footerVariant: FooterVariant.kitchenSink,
jobs: jobs || [],
errors: [...(jobsError ? [jobsError.message] : [])],
errors: combineErrors([jobsError]),
})
}
24 changes: 17 additions & 7 deletions pages/community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import EventsSection from '@src/components/page-sections/EventsSection'
import FeaturedContributorsSection from '@src/components/page-sections/FeaturedContributorsSection'
import { ScrollToLink } from '@src/components/ScrollToLink'
import { ResponsiveText } from '@src/components/Typography'
import { DISCORD_LINK } from '@src/consts'
import {
type Callouts,
getCommunityPageData,
Expand All @@ -28,6 +29,7 @@ import { getContributors } from '@src/data/getGithubData'
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps'

import { HeaderPad } from '../src/components/layout/HeaderPad'
import { combineErrors } from '../src/utils/combineErrors'

export default function Community({
contributors,
Expand Down Expand Up @@ -83,7 +85,7 @@ export default function Community({
target="_blank"
rel="noopener noreferrer"
startIcon={<DiscordIcon size={20} />}
href="https://discord.gg/pluralsh"
href={DISCORD_LINK}
>
Discord
</Button>
Expand Down Expand Up @@ -174,11 +176,19 @@ export const getStaticProps: GetStaticProps<CommunityPageProps> = async (
footerVariant: FooterVariant.kitchenSink,
events: events || [],
callouts: pageData.callouts,
errors: [
...(githubError ? [githubError] : []),
...(eventsError ? [eventsError] : []),
...(featuredContributorsError ? [featuredContributorsError] : []),
...(pageDataError ? [pageDataError] : []),
],
errors: combineErrors([
githubError,
eventsError,
featuredContributorsError,
pageDataError,
]),
})
}

type BaseError = {
name: string
message: string
}
export type FullError = BaseError & {
graphQLErrors?: readonly BaseError[] | undefined
}
7 changes: 2 additions & 5 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
StandardPageWidth,
} from '../src/components/layout/LayoutHelpers'
import { HomepageFeaturesSection } from '../src/components/page-sections/HomepageFeaturesSection'
import { combineErrors } from '../src/utils/combineErrors'

const HeroImagesSC = styled.div(({ theme: _theme }) => {
const baseWidth = 1432
Expand Down Expand Up @@ -585,10 +586,6 @@ export const getStaticProps = async () => {
featuredQuote: page?.featured_quote || null,
buildStackTabs,
footerVariant: FooterVariant.kitchenSink,
errors: [
...(error ? [`${error}`] : []),
...(stacksError ? [stacksError] : []),
...(reposError ? [reposError] : []),
],
errors: combineErrors([error, stacksError, reposError]),
})
}
3 changes: 2 additions & 1 deletion pages/legal/[legal].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getLegalPageData, getLegalPageSlugs } from '@src/data/getLegalPageData'
import { type MarkdownPageFragment } from '@src/generated/graphqlDirectus'
import { readMdPage } from '@src/markdoc/mdParser'
import { type MarkdocPage } from '@src/markdoc/mdSchema'
import { combineErrors } from '@src/utils/combineErrors'
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps'

import { HeaderPad } from '../../src/components/layout/HeaderPad'
Expand Down Expand Up @@ -133,6 +134,6 @@ export const getStaticProps: GetStaticProps<CommunityPageProps> = async (
title: page.title,
subtitle: page.subtitle,
markdoc,
errors: [...(pageDataError ? [pageDataError] : [])],
errors: combineErrors([pageDataError]),
})
}
7 changes: 2 additions & 5 deletions pages/marketplace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
type FaqListQueryVariables,
} from '@src/generated/graphqlDirectus'
import { type BasicRepoFragment } from '@src/generated/graphqlPlural'
import { combineErrors } from '@src/utils/combineErrors'
import {
type GlobalProps,
propsWithGlobalSettings,
Expand Down Expand Up @@ -612,10 +613,6 @@ export const getStaticProps: GetStaticProps<PageProps> = async () => {
tags: tags || [],
categories: categories || [],
faqs: normalizeM2mItems(faqData.collapsible_lists?.[0]) || [],
errors: [
...(reposError ? [reposError] : []),
...(stacksError ? [reposError] : []),
...(faqError ? [faqError] : []),
],
errors: combineErrors([reposError, stacksError, faqError]),
})
}
15 changes: 8 additions & 7 deletions pages/plural-stacks/[stack].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
type BasicRepoFragment,
type StackCollectionFragment,
} from '@src/generated/graphqlPlural'
import { combineErrors } from '@src/utils/combineErrors'
import {
type GlobalProps,
propsWithGlobalSettings,
Expand Down Expand Up @@ -400,12 +401,12 @@ export const getStaticProps: GetStaticProps<StackPageProps> = async (
(stackExtras.case_study?.stack_apps as string[]) || []
),
footerVariant: FooterVariant.kitchenSink,
errors: [
...(reposError ? [reposError] : []),
...(stacksError ? [stacksError] : []),
...(stackError ? [stackError] : []),
...(appError ? [appError] : []),
...(faqError ? [faqError] : []),
],
errors: combineErrors([
reposError,
stacksError,
stackError,
appError,
faqError,
]),
})
}
6 changes: 2 additions & 4 deletions pages/pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
type FaqListQuery,
type FaqListQueryVariables,
} from '@src/generated/graphqlDirectus'
import { combineErrors } from '@src/utils/combineErrors'
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps'
import { normalizeM2mItems } from '@src/utils/normalizeQuotes'

Expand Down Expand Up @@ -255,9 +256,6 @@ export const getStaticProps: GetStaticProps<PricingPageProps> = async (
...pricing,
faqs: normalizeM2mItems(faqData.collapsible_lists?.[0]) || [],
footerVariant: FooterVariant.kitchenSink,
errors: [
...(pricingError ? [pricingError] : []),
...(faqError ? [faqError] : []),
],
errors: combineErrors([pricingError, faqError]),
})
}
3 changes: 2 additions & 1 deletion pages/product.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { WhatIsPluralSection } from '@src/components/page-sections/WhatIsPluralS
import { CenteredSectionHead } from '@src/components/SectionHeads'
import { getProductPageData } from '@src/data/getProductPageData'
import { useAnimationPauser } from '@src/hooks/useAnimationPauser'
import { combineErrors } from '@src/utils/combineErrors'
import { propsWithGlobalSettings } from '@src/utils/getGlobalProps'
import { normalizeM2mItems } from '@src/utils/normalizeQuotes'

Expand Down Expand Up @@ -254,6 +255,6 @@ export const getStaticProps = async () => {
featuredQuote: pageData?.featured_quote,
faqs: normalizeM2mItems(pageData?.faq),
footerVariant: FooterVariant.kitchenSink,
errors: [...(pageDataError ? [pageDataError] : [])],
errors: combineErrors([pageDataError]),
})
}
8 changes: 2 additions & 6 deletions pages/solutions/[solution].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
type SolutionsSlugsQuery,
type SolutionsSlugsQueryVariables,
} from '@src/generated/graphqlDirectus'
import { combineErrors } from '@src/utils/combineErrors'
import {
type GlobalProps,
propsWithGlobalSettings,
Expand Down Expand Up @@ -248,11 +249,6 @@ export const getStaticProps: GetStaticProps<AppPageProps> = async (context) => {
featuredQuote: solution.featured_quote || null,
buildStackTabs,
footerVariant: FooterVariant.kitchenSink,
errors: [
...(solutionError ? [solutionError] : []),
...(faqError ? [faqError] : []),
...(reposError ? [reposError] : []),
...(stacksError ? [stacksError] : []),
],
errors: combineErrors([solutionError, faqError, reposError, stacksError]),
})
}
3 changes: 2 additions & 1 deletion src/components/BasicFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DiscordIcon } from '@pluralsh/design-system'
import styled from 'styled-components'

import { mqs } from '@src/breakpoints'
import { DISCORD_LINK } from '@src/consts'

import GithubStars from './GithubStars'
import { FullPageWidth } from './layout/LayoutHelpers'
Expand All @@ -15,7 +16,7 @@ export function BasicFooter({ className }: { className?: string }) {
<div className="socialIcons">
<SocialLink
className="discordIcon"
href="https://discord.gg/pluralsh"
href={DISCORD_LINK}
target="_blank"
rel="noopener noreferrer"
tabIndex={0}
Expand Down
3 changes: 2 additions & 1 deletion src/components/FooterNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styled from 'styled-components'
import { type ReadonlyDeep } from 'type-fest'

import { mqs } from '@src/breakpoints'
import { DISCORD_LINK } from '@src/consts'

import { FullPageWidth } from './layout/LayoutHelpers'
import { NewsletterSignupForm } from './NewsletterSignupForm'
Expand Down Expand Up @@ -90,7 +91,7 @@ const navItems = [
links: [
{
children: 'Discord',
href: 'https://discord.gg/pluralsh',
href: DISCORD_LINK,
target: '_blank',
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/components/NavigationMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isEmpty } from 'lodash-es'
import styled from 'styled-components'
import { useIsomorphicLayoutEffect } from 'usehooks-ts'

import { DISCORD_LINK } from '@src/consts'
import { useNavData } from '@src/contexts/NavDataContext'
import { type NavListFragment } from '@src/generated/graphqlDirectus'

Expand Down Expand Up @@ -98,7 +99,7 @@ function PluralMenuContent({
<NavList navData={navData} />
<SocialIcons>
<SocialLink
href="https://discord.gg/pluralsh"
href={DISCORD_LINK}
target="_blank"
rel="noopener noreferrer"
tabIndex={0}
Expand Down
4 changes: 3 additions & 1 deletion src/components/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { useKey } from 'rooks'
import styled, { StyleSheetManager, useTheme } from 'styled-components'
import { type Merge } from 'type-fest'

import { DISCORD_LINK } from '@src/consts'

import { breakpointIsGreaterOrEqual, mqs } from '../breakpoints'

import { useBreakpoint } from './contexts/BreakpointProvider'
Expand Down Expand Up @@ -95,7 +97,7 @@ export function PageHeader({
<div className="socialIcons">
<SocialLink
className="discordIcon"
href="https://discord.gg/pluralsh"
href={DISCORD_LINK}
target="_blank"
rel="noopener noreferrer"
tabIndex={0}
Expand Down
Loading

0 comments on commit 2383ec0

Please sign in to comment.