git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Improve license errors in psc-publish (#2082)
66107e5Harry Garrood
src/Language/PureScript/Publish.hs+6−2
@@ -216,8 +216,12 @@ getBowerRepositoryInfo = either (userError . BadRepositoryField) return . tryExt
216
216
217checkLicense :: PackageMeta -> PrepareM ()
217checkLicense :: PackageMeta -> PrepareM ()
218checkLicense pkgMeta =
218checkLicense pkgMeta =
219− unless (any isValidSPDX (bowerLicense pkgMeta))
219+ case bowerLicense pkgMeta of
220+ [] ->
220− (userError NoLicenseSpecified)
221+ userError NoLicenseSpecified
222+ ls ->
223+ unless (any isValidSPDX ls)
224+ (userError InvalidLicense)
221
225
222-- |
226-- |
223-- Check if a string is a valid SPDX license expression.
227-- Check if a string is a valid SPDX license expression.
src/Language/PureScript/Publish/ErrorsWarnings.hs+22−15
@@ -55,13 +55,13 @@ data PackageWarning
55-- | An error that should be fixed by the user.
55-- | An error that should be fixed by the user.
56data UserError
56data UserError
57 = BowerJSONNotFound
57 = BowerJSONNotFound
58− | LicenseNotFound
59 | BowerExecutableNotFound [String] -- list of executable names tried
58 | BowerExecutableNotFound [String] -- list of executable names tried
60 | CouldntDecodeBowerJSON (ParseError BowerError)
59 | CouldntDecodeBowerJSON (ParseError BowerError)
61 | TagMustBeCheckedOut
60 | TagMustBeCheckedOut
62 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
61 | AmbiguousVersions [Version] -- Invariant: should contain at least two elements
63 | BadRepositoryField RepositoryFieldError
62 | BadRepositoryField RepositoryFieldError
64 | NoLicenseSpecified
63 | NoLicenseSpecified
64+ | InvalidLicense
65 | MissingDependencies (NonEmpty PackageName)
65 | MissingDependencies (NonEmpty PackageName)
66 | CompileError P.MultipleErrors
66 | CompileError P.MultipleErrors
67 | DirtyWorkingTree
67 | DirtyWorkingTree
@@ -129,12 +129,6 @@ displayUserError e = case e of
129 "The bower.json file was not found. Please create one, or run " ++
129 "The bower.json file was not found. Please create one, or run " ++
130 "`pulp init`."
130 "`pulp init`."
131 )
131 )
132− LicenseNotFound ->
133− para (concat
134− ["No LICENSE file was found. Please create one. ",
135− "Distributing code without a license means that nobody ",
136− "will be able to (legally) use it."
137− ])
138 BowerExecutableNotFound names ->
132 BowerExecutableNotFound names ->
139 para (concat
133 para (concat
140 [ "The Bower executable was not found (tried: ", format names, "). Please"
134 [ "The Bower executable was not found (tried: ", format names, "). Please"
@@ -189,14 +183,7 @@ displayUserError e = case e of
189 , "following would be acceptable:"
183 , "following would be acceptable:"
190 ])
184 ])
191 , spacer
185 , spacer
192− ] ++
186+ ] ++ spdxExamples ++
193− map (indented . para)
194− [ "* \"MIT\""
195− , "* \"BSD-2-Clause\""
196− , "* \"GPL-2.0+\""
197− , "* \"(GPL-3.0 OR MIT)\""
198− ]
199− ++
200 [ spacer
187 [ spacer
201 , para (concat
188 , para (concat
202 [ "Note that distributing code without a license means that nobody "
189 [ "Note that distributing code without a license means that nobody "
@@ -209,6 +196,16 @@ displayUserError e = case e of
209 , "necessary."
196 , "necessary."
210 ])
197 ])
211 ]
198 ]
199+ InvalidLicense ->
200+ vcat $
201+ [ para (concat
202+ [ "The license specified in bower.json is not a valid SPDX license "
203+ , "expression. Please use the SPDX license expression format. For "
204+ , "example, any of the following would be acceptable:"
205+ ])
206+ , spacer
207+ ] ++
208+ spdxExamples
212 MissingDependencies pkgs ->
209 MissingDependencies pkgs ->
213 let singular = NonEmpty.length pkgs == 1
210 let singular = NonEmpty.length pkgs == 1
214 pl a b = if singular then b else a
211 pl a b = if singular then b else a
@@ -239,6 +236,16 @@ displayUserError e = case e of
239 "your changes first."
236 "your changes first."
240 )
237 )
241
238
239+spdxExamples :: [Box]
240+spdxExamples =
241+ map (indented . para)
242+ [ "* \"MIT\""
243+ , "* \"Apache-2.0\""
244+ , "* \"BSD-2-Clause\""
245+ , "* \"GPL-2.0+\""
246+ , "* \"(GPL-3.0 OR MIT)\""
247+ ]
248+
242displayRepositoryError :: RepositoryFieldError -> Box
249displayRepositoryError :: RepositoryFieldError -> Box
243displayRepositoryError err = case err of
250displayRepositoryError err = case err of
244 RepositoryFieldMissing ->
251 RepositoryFieldMissing ->