SystemCrafters Hack: Selecting from a list of notes with a specific tag

This is about a part of David Wilson’s SystemCrafters tutorials.
Sub-Topic “Selecting from a list of notes with a specific tag” in Tutorial " 5 Org Roam Hacks for Better Productivity in Emacs". The aim is to list all nodes with #+filetags: Project or create such a node if it does not exist yet when doing C-c n p.

I understand the explanations from its Video. But I got the error Symbol's value as variable is void: tag-name and do not understand why.

I have a (nearly minimal) working example with the relevant lines at the end. The orgroam-directory is set to ~/debug_orgroam. In the beginning when the directory is empty C-c n p works well and create a node with a #+filetags: Project in the heading. But when I do C-c n p a second time I receive the error. Restarting Emacs dosn’t help.

;; === Package setup ===
(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
			 ("org" . "https://orgmode.org/elpa/")
			 ("elpa" . "https://elpa.gnu.org/packages/")))
;; Initializes the package infrastructure
(package-initialize)

;; === use-package ==
;; use-package to simplify the config file
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(require 'use-package)
(setq use-package-always-ensure 't)

;; === EVIL
(use-package evil
  :init
  (setq evil-want-integration t)
  (setq evil-want-keybinding nil)
  (setq evil-want-C-i-jump nil)
  :config
  (evil-mode 1)
  ;; Use visual line motions even outside of visual-line-mode buffers
  (evil-global-set-key 'motion "j" 'evil-next-visual-line)
  (evil-global-set-key 'motion "k" 'evil-previous-visual-line)
  ;; Set "normal" vi-mode in specific buffers
  (evil-set-initial-state 'messages-buffer-mode 'normal)
  (evil-set-initial-state 'dashboard-mode 'normal)
  )

(use-package evil-collection
  :after evil
  :config
  (evil-collection-init)
  )

;; === ORG mode ------------
(defun buhtzology/org-mode-setup ()
  (org-indent-mode)
  (variable-pitch-mode 1)  ; variable-pitch fonts
  (visual-line-mode 1)
)

(use-package org
  :hook (org-mode . buhtzology/org-mode-setup)
  :config
  (setq org-ellipsis " ▽"  ; symbol behind folded headings
	org-hide-emphasis-markers t  ; do not show markdown text format chars
	)
)

(use-package org-roam
  :init  ; is called before the package is loaded
  (setq org-roam-v2-ack t)  ; do not show migration warning after startup
  :custom
  (org-roam-directory "~/debug_orgroam")
  (org-roam-completion-everywhere t)  ; use compleation-at-point NOT only
				      ; between brackets
  (org-roam-capture-templates  ; Keep in mind: store that templates in .org
			       ; files. Use (file "filename.org") for that.
   '(
     ("d" "default" plain  ; default incl. date
      "%?"
      :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
			 "#+title: ${title}\n+date: %U")
      :unnarrowed t)
      :unnarrowed t)
     ("p" "project" plain  ; see +filetags
      "* Goals\n\n%?\n\n* Tasks\n\n** TODO Add initial tasks\n\n* Dates\n\n"
      :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+filetags: Project")
      :unnarrowed t)
     )
  :config
  (org-roam-db-autosync-mode)
  )
  

;; NEW ========================
(defun my/org-roam-filter-by-tag (tag-name)
  (lambda (node)
    (member tag-name (org-roam-node-tags node))))

(defun my/org-roam-find-project ()
  (interactive)
  ;; Select a project file to open, creating it if necessary
  (org-roam-node-find
   nil
   nil
   (my/org-roam-filter-by-tag "Project")
   :templates
   '(("p" "project" plain "* Goals\n\n%?\n\n* Tasks\n\n** TODO Add initial tasks\n\n* Dates\n\n"
      :if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n#+category: ${title}\n#+filetags: Project")
      :unnarrowed t))))

(global-set-key (kbd "C-c n p") #'my/org-roam-find-project)
;; END NEW =====================

Side question: Because I am quit new to Emacs I would like to know for the next time how I could have investigate or solved such problems myself?

This line need to be in the init.el.

;; -*- lexical-binding: t; -*-

I do not know why and what it does. But it works then.