Catch composer json format errors and notify user

WIP-cache
Hugo Thunnissen 9 months ago
parent 7c76cbcc54
commit 8b6dc2eb38

@ -177,55 +177,62 @@ bareword typenames."))
((al phpinspect-autoloader) file) ((al phpinspect-autoloader) file)
(let* ((fs (phpinspect-project-fs (phpinspect-autoloader-project al))) (let* ((fs (phpinspect-project-fs (phpinspect-autoloader-project al)))
(project-root (file-name-directory (cdr file))) (project-root (file-name-directory (cdr file)))
(json (phpinspect--read-json-file fs (cdr file))) json autoload batch)
(autoload (gethash "autoload" json))
batch)
(when (hash-table-p autoload) (condition-case err
(maphash (setq json (phpinspect--read-json-file fs (cdr file)))
(lambda (type prefixes) (t (message "Error parsing composer json at %s : %s " (cdr file) err)))
(let ((strategy))
(pcase type (when json
("psr-0" (setq autoload (gethash "autoload" json))
(maphash
(lambda (prefix directory-paths) (when (hash-table-p autoload)
(when (stringp directory-paths) (maphash
(setq directory-paths (list directory-paths))) (lambda (type prefixes)
(setq strategy (phpinspect-make-psr0-generated (let ((strategy))
:autoloader al (pcase type
:fs fs ("psr-0"
:prefix prefix (maphash
:own (eq 'local (car file)))) (lambda (prefix directory-paths)
(dolist (path directory-paths) (when (stringp directory-paths)
(push (file-name-concat project-root path) (setq directory-paths (list directory-paths)))
(phpinspect-psr0-directories strategy))) (setq strategy (phpinspect-make-psr0-generated
(push strategy batch)) :autoloader al
prefixes)) :fs fs
("psr-4" :prefix prefix
(maphash :own (eq 'local (car file))))
(lambda (prefix directory-paths) (dolist (path directory-paths)
(when (stringp directory-paths) (push (file-name-concat project-root path)
(setq directory-paths (list directory-paths))) (phpinspect-psr0-directories strategy)))
(setq strategy (phpinspect-make-psr4-generated (push strategy batch))
:fs fs prefixes))
:autoloader al ("psr-4"
:prefix prefix (maphash
:own (eq 'local (car file)))) (lambda (prefix directory-paths)
(dolist (path directory-paths) (when (stringp directory-paths)
(push (file-name-concat project-root path) (setq directory-paths (list directory-paths)))
(phpinspect-psr4-directories strategy))) (setq strategy (phpinspect-make-psr4-generated
(push strategy batch)) :fs fs
prefixes)) :autoloader al
("files" :prefix prefix
(setq strategy :own (eq 'local (car file))))
(phpinspect-make-files (dolist (path directory-paths)
:list (mapcar (push (file-name-concat project-root path)
(lambda (file) (file-name-concat project-root file)) (phpinspect-psr4-directories strategy)))
prefixes) (push strategy batch))
:autoloader al)) prefixes))
(push strategy batch)) ("files"
(_ (phpinspect--log "Unsupported autoload strategy \"%s\" encountered" type))))) (setq strategy
autoload) (phpinspect-make-files
(phpinspect-pipeline-emit-all batch)))) :list (mapcar
(lambda (file) (file-name-concat project-root file))
prefixes)
:autoloader al))
(push strategy batch))
(_ (phpinspect--log "Unsupported autoload strategy \"%s\" encountered" type)))))
autoload)
(phpinspect-pipeline-emit-all batch)))))
(cl-defmethod phpinspect-autoloader-resolve ((autoloader phpinspect-autoloader) (cl-defmethod phpinspect-autoloader-resolve ((autoloader phpinspect-autoloader)

Loading…
Cancel
Save