How to trigger event before Document cancellation and before Cancal Linked Document MSG

I have some Validationes that I want to perform in the leave application, these checks need to be performed before canceling but what happened is that the system canceled the associated document (attendance) and then executed the code

i tried before cancel and in cancale triggers

@nextgen you can throw an exception if you want to revert the changes

i already throw an exception on (before cancel and on cancel events ) but the exception executed after the linked documents has been already cancelled

the issue here that

frappe.desk.form.linked_with.get_submitted_linked_docs

called before

frappe.desk.form.save.cancel

i used monkey batch to solve this issue temporary

import frappe
from frappe.desk.form.linked_with import get_submitted_linked_docs
original_get_submitted_linked_docs = get_submitted_linked_docs

@frappe.whitelist()
def get_submitted_linked_docs(doctype: str, name: str) -> list[tuple]:
	res = frappe.get_doc(doctype, name).run_method('before_cancel')
	# if  return value of 'before_cancel' equal true will skip the linked documents validations 
	# and show the delete confirmation massage direct and you can handel the remain code 
	# after delete confiramtion by stander event on_cancel
	if res == True:
		return {'docs': [], 'count': 0}
	return original_get_submitted_linked_docs (doctype ,name)

frappe.desk.form.linked_with.get_submitted_linked_docs = get_submitted_linked_docs

if someone have solution better please provide