From fcb26769affd79c864d32ec4595fff13bd4f74bb Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Fri, 1 Nov 2024 14:22:46 +0000 Subject: [PATCH] Error if a README couldn't be found (#1167) * Error if a README couldn't be found GetRemote returns nil not an error in this case * Fail the build on unrecognised block types This should be very rare, but always points at a significant error we need to fix. --- common-theme/layouts/partials/block/block.html | 2 +- common-theme/layouts/partials/block/readme.html | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common-theme/layouts/partials/block/block.html b/common-theme/layouts/partials/block/block.html index a9b3b8e21..4b6253498 100644 --- a/common-theme/layouts/partials/block/block.html +++ b/common-theme/layouts/partials/block/block.html @@ -21,5 +21,5 @@ {{ else if eq $blockData.type "link" }} {{ partial "block/link.html" . }} {{ else }} -

Error: {{ $blockData.type }} Unrecognized block type

+ {{ errorf "Unrecognized block type %s" $blockData.type }} {{ end }} diff --git a/common-theme/layouts/partials/block/readme.html b/common-theme/layouts/partials/block/readme.html index 7952645a0..eaccc86fc 100644 --- a/common-theme/layouts/partials/block/readme.html +++ b/common-theme/layouts/partials/block/readme.html @@ -1,6 +1,14 @@ {{ $blockData := .Page.Scratch.Get "blockData" }} + {{ $pageContext := . }} -{{ with resources.GetRemote $blockData.api $blockData.headers }} +{{ $response := resources.GetRemote $blockData.api $blockData.headers }} + +{{/* 404s lead to GetRemote returning nil rather than an error. */}} +{{ if eq $response nil }} + {{ errorf "Couldn't find readme at %s" $blockData.api }} +{{ end }} + +{{ with $response }} {{ with .Err }} {{ errorf "Failed %s on %s. Error: %s" $blockData.api .Page.Title .Err }} {{ end }}